mirror of
https://github.com/django/django.git
synced 2025-08-30 23:37:50 +00:00
Merged regressiontests and modeltests into the test root.
This commit is contained in:
parent
b3d2ccb5bf
commit
89f40e3624
1050 changed files with 0 additions and 0 deletions
83
tests/multiple_database/models.py
Normal file
83
tests/multiple_database/models.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Review(models.Model):
|
||||
source = models.CharField(max_length=100)
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = generic.GenericForeignKey()
|
||||
|
||||
def __str__(self):
|
||||
return self.source
|
||||
|
||||
class Meta:
|
||||
ordering = ('source',)
|
||||
|
||||
class PersonManager(models.Manager):
|
||||
def get_by_natural_key(self, name):
|
||||
return self.get(name=name)
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Person(models.Model):
|
||||
objects = PersonManager()
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
|
||||
# This book manager doesn't do anything interesting; it just
|
||||
# exists to strip out the 'extra_arg' argument to certain
|
||||
# calls. This argument is used to establish that the BookManager
|
||||
# is actually getting used when it should be.
|
||||
class BookManager(models.Manager):
|
||||
def create(self, *args, **kwargs):
|
||||
kwargs.pop('extra_arg', None)
|
||||
return super(BookManager, self).create(*args, **kwargs)
|
||||
|
||||
def get_or_create(self, *args, **kwargs):
|
||||
kwargs.pop('extra_arg', None)
|
||||
return super(BookManager, self).get_or_create(*args, **kwargs)
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Book(models.Model):
|
||||
objects = BookManager()
|
||||
title = models.CharField(max_length=100)
|
||||
published = models.DateField()
|
||||
authors = models.ManyToManyField(Person)
|
||||
editor = models.ForeignKey(Person, null=True, related_name='edited')
|
||||
reviews = generic.GenericRelation(Review)
|
||||
pages = models.IntegerField(default=100)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
ordering = ('title',)
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Pet(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
owner = models.ForeignKey(Person)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
|
||||
class UserProfile(models.Model):
|
||||
user = models.OneToOneField(User, null=True)
|
||||
flavor = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
ordering = ('flavor',)
|
Loading…
Add table
Add a link
Reference in a new issue