From 3f115776e1ffaf7b48976f88faf36c423e544d1d Mon Sep 17 00:00:00 2001 From: Jason Myers Date: Sat, 2 Nov 2013 17:50:35 -0500 Subject: [PATCH] PEP8 Signed-off-by: Jason Myers --- tests/admin_views/admin.py | 22 +++++++++++ tests/decorators/tests.py | 3 +- tests/defer/models.py | 4 ++ tests/defer_regress/models.py | 14 +++++++ tests/model_forms/tests.py | 11 ++++-- tests/model_forms_regress/models.py | 12 ++++++ tests/model_forms_regress/tests.py | 7 +++- tests/model_formsets/models.py | 26 +++++++++++++ tests/model_formsets_regress/models.py | 6 +++ tests/model_formsets_regress/tests.py | 1 + tests/model_inheritance/models.py | 22 +++++++++++ tests/model_inheritance_regress/models.py | 37 +++++++++++++++++++ .../models.py | 2 + tests/model_validation/models.py | 1 + tests/modeladmin/models.py | 3 ++ tests/multiple_database/models.py | 6 +++ 16 files changed, 172 insertions(+), 5 deletions(-) diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index 2aa96fbafa..039383a7dc 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -58,6 +58,7 @@ class ArticleInline(admin.TabularInline): }) ) + class ChapterInline(admin.TabularInline): model = Chapter @@ -578,10 +579,12 @@ class AdminOrderedFieldAdmin(admin.ModelAdmin): ordering = ('order',) list_display = ('stuff', 'order') + class AdminOrderedModelMethodAdmin(admin.ModelAdmin): ordering = ('order',) list_display = ('stuff', 'some_order') + class AdminOrderedAdminMethodAdmin(admin.ModelAdmin): def some_admin_order(self, obj): return obj.order @@ -589,13 +592,17 @@ class AdminOrderedAdminMethodAdmin(admin.ModelAdmin): ordering = ('order',) list_display = ('stuff', 'some_admin_order') + def admin_ordered_callable(obj): return obj.order admin_ordered_callable.admin_order_field = 'order' + + class AdminOrderedCallableAdmin(admin.ModelAdmin): ordering = ('order',) list_display = ('stuff', admin_ordered_callable) + class ReportAdmin(admin.ModelAdmin): def extra(self, request): return HttpResponse() @@ -612,6 +619,7 @@ class ReportAdmin(admin.ModelAdmin): class CustomTemplateBooleanFieldListFilter(BooleanFieldListFilter): template = 'custom_filter_template.html' + class CustomTemplateFilterColorAdmin(admin.ModelAdmin): list_filter = (('warm', CustomTemplateBooleanFieldListFilter),) @@ -628,12 +636,14 @@ class RelatedPrepopulatedInline1(admin.StackedInline): prepopulated_fields = {'slug1': ['name', 'pubdate'], 'slug2': ['status', 'name']} + class RelatedPrepopulatedInline2(admin.TabularInline): model = RelatedPrepopulated extra = 1 prepopulated_fields = {'slug1': ['name', 'pubdate'], 'slug2': ['status', 'name']} + class MainPrepopulatedAdmin(admin.ModelAdmin): inlines = [RelatedPrepopulatedInline1, RelatedPrepopulatedInline2] fieldsets = ( @@ -712,14 +722,17 @@ class FormWithoutHiddenField(forms.ModelForm): first = forms.CharField() second = forms.CharField() + class FormWithoutVisibleField(forms.ModelForm): first = forms.CharField(widget=forms.HiddenInput) second = forms.CharField(widget=forms.HiddenInput) + class FormWithVisibleAndHiddenField(forms.ModelForm): first = forms.CharField(widget=forms.HiddenInput) second = forms.CharField() + class EmptyModelVisibleAdmin(admin.ModelAdmin): form = FormWithoutHiddenField fieldsets = ( @@ -728,39 +741,48 @@ class EmptyModelVisibleAdmin(admin.ModelAdmin): }), ) + class EmptyModelHiddenAdmin(admin.ModelAdmin): form = FormWithoutVisibleField fieldsets = EmptyModelVisibleAdmin.fieldsets + class EmptyModelMixinAdmin(admin.ModelAdmin): form = FormWithVisibleAndHiddenField fieldsets = EmptyModelVisibleAdmin.fieldsets + class CityInlineAdmin(admin.TabularInline): model = City view_on_site = False + class StateAdmin(admin.ModelAdmin): inlines = [CityInlineAdmin] + class RestaurantInlineAdmin(admin.TabularInline): model = Restaurant view_on_site = True + class CityAdmin(admin.ModelAdmin): inlines = [RestaurantInlineAdmin] view_on_site = True + class WorkerAdmin(admin.ModelAdmin): def view_on_site(self, obj): return '/worker/%s/%s/' % (obj.surname, obj.name) + class WorkerInlineAdmin(admin.TabularInline): model = Worker def view_on_site(self, obj): return '/worker_inline/%s/%s/' % (obj.surname, obj.name) + class RestaurantAdmin(admin.ModelAdmin): inlines = [WorkerInlineAdmin] view_on_site = False diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py index 4016273ef5..db00f36051 100644 --- a/tests/decorators/tests.py +++ b/tests/decorators/tests.py @@ -44,7 +44,7 @@ full_decorator = compose( vary_on_cookie, # django.views.decorators.cache - cache_page(60*15), + cache_page(60 * 15), cache_control(private=True), never_cache, @@ -65,6 +65,7 @@ full_decorator = compose( fully_decorated = full_decorator(fully_decorated) + class DecoratorsTest(TestCase): def test_attributes(self): diff --git a/tests/defer/models.py b/tests/defer/models.py index cf3bae86bb..ffc8a0c2c7 100644 --- a/tests/defer/models.py +++ b/tests/defer/models.py @@ -10,6 +10,7 @@ class Secondary(models.Model): first = models.CharField(max_length=50) second = models.CharField(max_length=50) + @python_2_unicode_compatible class Primary(models.Model): name = models.CharField(max_length=50) @@ -19,12 +20,15 @@ class Primary(models.Model): def __str__(self): return self.name + class Child(Primary): pass + class BigChild(Primary): other = models.CharField(max_length=50) + class ChildProxy(Child): class Meta: proxy = True diff --git a/tests/defer_regress/models.py b/tests/defer_regress/models.py index 0170221cb9..d858558e97 100644 --- a/tests/defer_regress/models.py +++ b/tests/defer_regress/models.py @@ -16,13 +16,16 @@ class Item(models.Model): def __str__(self): return self.name + class RelatedItem(models.Model): item = models.ForeignKey(Item) + class Child(models.Model): name = models.CharField(max_length=10) value = models.IntegerField() + @python_2_unicode_compatible class Leaf(models.Model): name = models.CharField(max_length=10) @@ -33,14 +36,17 @@ class Leaf(models.Model): def __str__(self): return self.name + class ResolveThis(models.Model): num = models.FloatField() name = models.CharField(max_length=16) + class Proxy(Item): class Meta: proxy = True + @python_2_unicode_compatible class SimpleItem(models.Model): name = models.CharField(max_length=15) @@ -49,29 +55,37 @@ class SimpleItem(models.Model): def __str__(self): return self.name + class Feature(models.Model): item = models.ForeignKey(SimpleItem) + class SpecialFeature(models.Model): feature = models.ForeignKey(Feature) + class OneToOneItem(models.Model): item = models.OneToOneField(Item, related_name="one_to_one_item") name = models.CharField(max_length=15) + class ItemAndSimpleItem(models.Model): item = models.ForeignKey(Item) simple = models.ForeignKey(SimpleItem) + class Profile(models.Model): profile1 = models.CharField(max_length=1000, default='profile1') + class Location(models.Model): location1 = models.CharField(max_length=1000, default='location1') + class Item(models.Model): pass + class Request(models.Model): profile = models.ForeignKey(Profile, null=True, blank=True) location = models.ForeignKey(Location) diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index ddc7a4ceef..5e443011c2 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -185,6 +185,7 @@ class BetterWriterForm(forms.ModelForm): model = BetterWriter fields = '__all__' + class WriterProfileForm(forms.ModelForm): class Meta: model = WriterProfile @@ -234,6 +235,7 @@ class ColourfulItemForm(forms.ModelForm): # model forms for testing work on #9321: + class StatusNoteForm(forms.ModelForm): class Meta: model = ArticleStatusNote @@ -295,7 +297,7 @@ class ModelFormBaseTest(TestCase): fields = '__all__' self.assertIsInstance(ReplaceField.base_fields['url'], - forms.fields.BooleanField) + forms.fields.BooleanField) def test_replace_field_variant_2(self): # Should have the same result as before, @@ -308,7 +310,7 @@ class ModelFormBaseTest(TestCase): fields = ['url'] self.assertIsInstance(ReplaceField.base_fields['url'], - forms.fields.BooleanField) + forms.fields.BooleanField) def test_replace_field_variant_3(self): # Should have the same result as before, @@ -321,7 +323,7 @@ class ModelFormBaseTest(TestCase): fields = [] # url will still appear, since it is explicit above self.assertIsInstance(ReplaceField.base_fields['url'], - forms.fields.BooleanField) + forms.fields.BooleanField) def test_override_field(self): class WriterForm(forms.ModelForm): @@ -583,6 +585,7 @@ class IncompleteCategoryFormWithFields(forms.ModelForm): fields = ('name', 'slug') model = Category + class IncompleteCategoryFormWithExclude(forms.ModelForm): """ A form that replaces the model's url field with a custom one. This should @@ -788,6 +791,7 @@ class UniqueTest(TestCase): "slug": "Django 1.0"}, instance=p) self.assertTrue(form.is_valid()) + class ModelToDictTests(TestCase): """ Tests for forms.models.model_to_dict @@ -824,6 +828,7 @@ class ModelToDictTests(TestCase): # Ensure many-to-many relation appears as a list self.assertIsInstance(d['categories'], list) + class OldFormForXTests(TestCase): def test_base_form(self): self.assertEqual(Category.objects.count(), 0) diff --git a/tests/model_forms_regress/models.py b/tests/model_forms_regress/models.py index 2c2fd39158..396bd1eaa4 100644 --- a/tests/model_forms_regress/models.py +++ b/tests/model_forms_regress/models.py @@ -11,6 +11,7 @@ from django.utils._os import upath class Person(models.Model): name = models.CharField(max_length=100) + class Triple(models.Model): left = models.IntegerField() middle = models.IntegerField() @@ -19,9 +20,11 @@ class Triple(models.Model): class Meta: unique_together = (('left', 'middle'), ('middle', 'right')) + class FilePathModel(models.Model): path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True) + @python_2_unicode_compatible class Publication(models.Model): title = models.CharField(max_length=30) @@ -30,6 +33,7 @@ class Publication(models.Model): def __str__(self): return self.title + @python_2_unicode_compatible class Article(models.Model): headline = models.CharField(max_length=100) @@ -38,15 +42,18 @@ class Article(models.Model): def __str__(self): return self.headline + class CustomFileField(models.FileField): def save_form_data(self, instance, data): been_here = getattr(self, 'been_saved', False) assert not been_here, "save_form_data called more than once" setattr(self, 'been_saved', True) + class CustomFF(models.Model): f = CustomFileField(upload_to='unused', blank=True) + class RealPerson(models.Model): name = models.CharField(max_length=100) @@ -54,20 +61,25 @@ class RealPerson(models.Model): if self.name.lower() == 'anonymous': raise ValidationError("Please specify a real name.") + class Author(models.Model): publication = models.OneToOneField(Publication, null=True, blank=True) full_name = models.CharField(max_length=255) + class Author1(models.Model): publication = models.OneToOneField(Publication, null=False) full_name = models.CharField(max_length=255) + class Homepage(models.Model): url = models.URLField() + class Document(models.Model): myfile = models.FileField(upload_to='unused', blank=True) + class Edition(models.Model): author = models.ForeignKey(Person) publication = models.ForeignKey(Publication) diff --git a/tests/model_forms_regress/tests.py b/tests/model_forms_regress/tests.py index b7f4cf5979..963c7e552d 100644 --- a/tests/model_forms_regress/tests.py +++ b/tests/model_forms_regress/tests.py @@ -106,6 +106,7 @@ class FullyLocalizedTripleForm(forms.ModelForm): localized_fields = '__all__' fields = '__all__' + class LocalizedModelFormTest(TestCase): def test_model_form_applies_localize_to_some_fields(self): f = PartiallyLocalizedTripleForm({'left': 10, 'middle': 10, 'right': 10}) @@ -167,6 +168,7 @@ class FilePathFieldTests(TestCase): names.sort() self.assertEqual(names, ['---------', '__init__.py', 'models.py', 'tests.py']) + class ManyToManyCallableInitialTests(TestCase): def test_callable(self): "Regression for #10349: A callable can be provided as the initial value for an m2m field" @@ -207,9 +209,10 @@ class CustomFieldSaveTests(TestCase): # It's enough that the form saves without error -- the custom save routine will # generate an AssertionError if it is called more than once during save. - form = CFFForm(data = {'f': None}) + form = CFFForm(data={'f': None}) form.save() + class ModelChoiceIteratorTests(TestCase): def test_len(self): class Form(forms.ModelForm): @@ -236,12 +239,14 @@ class CustomModelFormSaveMethod(TestCase): self.assertEqual(form.is_valid(), False) self.assertEqual(form.errors['__all__'], ['Please specify a real name.']) + class ModelClassTests(TestCase): def test_no_model_class(self): class NoModelModelForm(forms.ModelForm): pass self.assertRaises(ValueError, NoModelModelForm) + class OneToOneFieldTests(TestCase): def test_assignment_of_none(self): class AuthorForm(forms.ModelForm): diff --git a/tests/model_formsets/models.py b/tests/model_formsets/models.py index adeb3455a4..da79c6a573 100644 --- a/tests/model_formsets/models.py +++ b/tests/model_formsets/models.py @@ -17,9 +17,11 @@ class Author(models.Model): def __str__(self): return self.name + class BetterAuthor(Author): write_speed = models.IntegerField() + @python_2_unicode_compatible class Book(models.Model): author = models.ForeignKey(Author) @@ -34,6 +36,7 @@ class Book(models.Model): def __str__(self): return self.title + @python_2_unicode_compatible class BookWithCustomPK(models.Model): my_pk = models.DecimalField(max_digits=5, decimal_places=0, primary_key=True) @@ -43,9 +46,11 @@ class BookWithCustomPK(models.Model): def __str__(self): return '%s: %s' % (self.my_pk, self.title) + class Editor(models.Model): name = models.CharField(max_length=100) + @python_2_unicode_compatible class BookWithOptionalAltEditor(models.Model): author = models.ForeignKey(Author) @@ -61,6 +66,7 @@ class BookWithOptionalAltEditor(models.Model): def __str__(self): return self.title + @python_2_unicode_compatible class AlternateBook(Book): notes = models.CharField(max_length=100) @@ -68,6 +74,7 @@ class AlternateBook(Book): def __str__(self): return '%s - %s' % (self.title, self.notes) + @python_2_unicode_compatible class AuthorMeeting(models.Model): name = models.CharField(max_length=100) @@ -77,6 +84,7 @@ class AuthorMeeting(models.Model): def __str__(self): return self.name + class CustomPrimaryKey(models.Model): my_pk = models.CharField(max_length=10, primary_key=True) some_field = models.CharField(max_length=100) @@ -84,6 +92,7 @@ class CustomPrimaryKey(models.Model): # models for inheritance tests. + @python_2_unicode_compatible class Place(models.Model): name = models.CharField(max_length=50) @@ -92,6 +101,7 @@ class Place(models.Model): def __str__(self): return self.name + @python_2_unicode_compatible class Owner(models.Model): auto_id = models.AutoField(primary_key=True) @@ -101,12 +111,14 @@ class Owner(models.Model): def __str__(self): return "%s at %s" % (self.name, self.place) + class Location(models.Model): place = models.ForeignKey(Place, unique=True) # this is purely for testing the data doesn't matter here :) lat = models.CharField(max_length=100) lon = models.CharField(max_length=100) + @python_2_unicode_compatible class OwnerProfile(models.Model): owner = models.OneToOneField(Owner, primary_key=True) @@ -115,6 +127,7 @@ class OwnerProfile(models.Model): def __str__(self): return "%s is %d" % (self.owner.name, self.age) + @python_2_unicode_compatible class Restaurant(Place): serves_pizza = models.BooleanField(default=False) @@ -122,6 +135,7 @@ class Restaurant(Place): def __str__(self): return self.name + @python_2_unicode_compatible class Product(models.Model): slug = models.SlugField(unique=True) @@ -129,6 +143,7 @@ class Product(models.Model): def __str__(self): return self.slug + @python_2_unicode_compatible class Price(models.Model): price = models.DecimalField(max_digits=10, decimal_places=2) @@ -140,13 +155,16 @@ class Price(models.Model): class Meta: unique_together = (('price', 'quantity'),) + class MexicanRestaurant(Restaurant): serves_tacos = models.BooleanField(default=False) + class ClassyMexicanRestaurant(MexicanRestaurant): restaurant = models.OneToOneField(MexicanRestaurant, parent_link=True, primary_key=True) tacos_are_yummy = models.BooleanField(default=False) + # models for testing unique_together validation when a fk is involved and # using inlineformset_factory. @python_2_unicode_compatible @@ -156,6 +174,7 @@ class Repository(models.Model): def __str__(self): return self.name + @python_2_unicode_compatible class Revision(models.Model): repository = models.ForeignKey(Repository) @@ -167,21 +186,25 @@ class Revision(models.Model): def __str__(self): return "%s (%s)" % (self.revision, six.text_type(self.repository)) + # models for testing callable defaults (see bug #7975). If you define a model # with a callable default value, you cannot rely on the initial value in a # form. class Person(models.Model): name = models.CharField(max_length=128) + class Membership(models.Model): person = models.ForeignKey(Person) date_joined = models.DateTimeField(default=datetime.datetime.now) karma = models.IntegerField() + # models for testing a null=True fk to a parent class Team(models.Model): name = models.CharField(max_length=100) + @python_2_unicode_compatible class Player(models.Model): team = models.ForeignKey(Team, null=True) @@ -190,6 +213,7 @@ class Player(models.Model): def __str__(self): return self.name + # Models for testing custom ModelForm save methods in formsets and inline formsets @python_2_unicode_compatible class Poet(models.Model): @@ -198,6 +222,7 @@ class Poet(models.Model): def __str__(self): return self.name + @python_2_unicode_compatible class Poem(models.Model): poet = models.ForeignKey(Poet) @@ -206,6 +231,7 @@ class Poem(models.Model): def __str__(self): return self.name + @python_2_unicode_compatible class Post(models.Model): title = models.CharField(max_length=50, unique_for_date='posted', blank=True) diff --git a/tests/model_formsets_regress/models.py b/tests/model_formsets_regress/models.py index f94ad51929..58eed6a22b 100644 --- a/tests/model_formsets_regress/models.py +++ b/tests/model_formsets_regress/models.py @@ -6,23 +6,29 @@ class User(models.Model): username = models.CharField(max_length=12, unique=True) serial = models.IntegerField() + class UserSite(models.Model): user = models.ForeignKey(User, to_field="username") data = models.IntegerField() + class Place(models.Model): name = models.CharField(max_length=50) + class Restaurant(Place): pass + class Manager(models.Model): retaurant = models.ForeignKey(Restaurant) name = models.CharField(max_length=50) + class Network(models.Model): name = models.CharField(max_length=15) + @python_2_unicode_compatible class Host(models.Model): network = models.ForeignKey(Network) diff --git a/tests/model_formsets_regress/tests.py b/tests/model_formsets_regress/tests.py index f8a5b7b3ac..7d400d2f87 100644 --- a/tests/model_formsets_regress/tests.py +++ b/tests/model_formsets_regress/tests.py @@ -330,6 +330,7 @@ class FormfieldCallbackTests(TestCase): formfield_callback=callback) self.assertCallbackCalled(callback) + class BaseCustomDeleteFormSet(BaseFormSet): """ A formset mix-in that lets a form decide if it's to be deleted. diff --git a/tests/model_inheritance/models.py b/tests/model_inheritance/models.py index 020bb35bc7..7f5702da59 100644 --- a/tests/model_inheritance/models.py +++ b/tests/model_inheritance/models.py @@ -20,6 +20,7 @@ from django.utils.encoding import python_2_unicode_compatible # Abstract base classes # + @python_2_unicode_compatible class CommonInfo(models.Model): name = models.CharField(max_length=50) @@ -32,18 +33,22 @@ class CommonInfo(models.Model): def __str__(self): return '%s %s' % (self.__class__.__name__, self.name) + class Worker(CommonInfo): job = models.CharField(max_length=50) + class Student(CommonInfo): school_class = models.CharField(max_length=10) class Meta: pass + class StudentWorker(Student, Worker): pass + # # Abstract base classes with related models # @@ -51,6 +56,7 @@ class StudentWorker(Student, Worker): class Post(models.Model): title = models.CharField(max_length=50) + @python_2_unicode_compatible class Attachment(models.Model): post = models.ForeignKey(Post, related_name='attached_%(class)s_set') @@ -62,12 +68,15 @@ class Attachment(models.Model): def __str__(self): return self.content + class Comment(Attachment): is_spam = models.BooleanField(default=False) + class Link(Attachment): url = models.URLField() + # # Multi-table inheritance # @@ -79,6 +88,7 @@ class Chef(models.Model): def __str__(self): return "%s the chef" % self.name + @python_2_unicode_compatible class Place(models.Model): name = models.CharField(max_length=50) @@ -87,6 +97,7 @@ class Place(models.Model): def __str__(self): return "%s the place" % self.name + class Rating(models.Model): rating = models.IntegerField(null=True, blank=True) @@ -94,6 +105,7 @@ class Rating(models.Model): abstract = True ordering = ['-rating'] + @python_2_unicode_compatible class Restaurant(Place, Rating): serves_hot_dogs = models.BooleanField(default=False) @@ -106,6 +118,7 @@ class Restaurant(Place, Rating): def __str__(self): return "%s the restaurant" % self.name + @python_2_unicode_compatible class ItalianRestaurant(Restaurant): serves_gnocchi = models.BooleanField(default=False) @@ -113,6 +126,7 @@ class ItalianRestaurant(Restaurant): def __str__(self): return "%s the italian restaurant" % self.name + @python_2_unicode_compatible class Supplier(Place): customers = models.ManyToManyField(Restaurant, related_name='provider') @@ -120,6 +134,7 @@ class Supplier(Place): def __str__(self): return "%s the supplier" % self.name + @python_2_unicode_compatible class ParkingLot(Place): # An explicit link to the parent (we can control the attribute name). @@ -129,6 +144,7 @@ class ParkingLot(Place): def __str__(self): return "%s the parking lot" % self.name + # # Abstract base classes with related models where the sub-class has the # same name in a different app and inherits from the same abstract base @@ -141,6 +157,7 @@ class ParkingLot(Place): class Title(models.Model): title = models.CharField(max_length=50) + class NamedURL(models.Model): title = models.ForeignKey(Title, related_name='attached_%(app_label)s_%(class)s_set') url = models.URLField() @@ -148,6 +165,7 @@ class NamedURL(models.Model): class Meta: abstract = True + @python_2_unicode_compatible class Copy(NamedURL): content = models.TextField() @@ -155,16 +173,20 @@ class Copy(NamedURL): def __str__(self): return self.content + class Mixin(object): def __init__(self): self.other_attr = 1 super(Mixin, self).__init__() + class MixinModel(models.Model, Mixin): pass + class Base(models.Model): titles = models.ManyToManyField(Title) + class SubBase(Base): sub_id = models.IntegerField(primary_key=True) diff --git a/tests/model_inheritance_regress/models.py b/tests/model_inheritance_regress/models.py index 04febf54a6..53752b6948 100644 --- a/tests/model_inheritance_regress/models.py +++ b/tests/model_inheritance_regress/models.py @@ -5,6 +5,7 @@ import datetime from django.db import models from django.utils.encoding import python_2_unicode_compatible + @python_2_unicode_compatible class Place(models.Model): name = models.CharField(max_length=50) @@ -16,6 +17,7 @@ class Place(models.Model): def __str__(self): return "%s the place" % self.name + @python_2_unicode_compatible class Restaurant(Place): serves_hot_dogs = models.BooleanField(default=False) @@ -24,6 +26,7 @@ class Restaurant(Place): def __str__(self): return "%s the restaurant" % self.name + @python_2_unicode_compatible class ItalianRestaurant(Restaurant): serves_gnocchi = models.BooleanField(default=False) @@ -31,6 +34,7 @@ class ItalianRestaurant(Restaurant): def __str__(self): return "%s the italian restaurant" % self.name + @python_2_unicode_compatible class ParkingLot(Place): # An explicit link to the parent (we can control the attribute name). @@ -40,16 +44,19 @@ class ParkingLot(Place): def __str__(self): return "%s the parking lot" % self.name + class ParkingLot2(Place): # In lieu of any other connector, an existing OneToOneField will be # promoted to the primary key. parent = models.OneToOneField(Place) + class ParkingLot3(Place): # The parent_link connector need not be the pk on the model. primary_key = models.AutoField(primary_key=True) parent = models.OneToOneField(Place, parent_link=True) + class ParkingLot4(models.Model): # Test parent_link connector can be discovered in abstract classes. parent = models.OneToOneField(Place, parent_link=True) @@ -57,31 +64,40 @@ class ParkingLot4(models.Model): class Meta: abstract = True + class ParkingLot4A(ParkingLot4, Place): pass + class ParkingLot4B(Place, ParkingLot4): pass + class Supplier(models.Model): restaurant = models.ForeignKey(Restaurant) + class Wholesaler(Supplier): retailer = models.ForeignKey(Supplier, related_name='wholesale_supplier') + class Parent(models.Model): created = models.DateTimeField(default=datetime.datetime.now) + class Child(Parent): name = models.CharField(max_length=10) + class SelfRefParent(models.Model): parent_data = models.IntegerField() self_data = models.ForeignKey('self', null=True) + class SelfRefChild(SelfRefParent): child_data = models.IntegerField() + @python_2_unicode_compatible class Article(models.Model): headline = models.CharField(max_length=100) @@ -93,24 +109,30 @@ class Article(models.Model): def __str__(self): return self.headline + class ArticleWithAuthor(Article): author = models.CharField(max_length=100) + class M2MBase(models.Model): articles = models.ManyToManyField(Article) + class M2MChild(M2MBase): name = models.CharField(max_length=50) + class Evaluation(Article): quality = models.IntegerField() class Meta: abstract = True + class QualityControl(Evaluation): assignee = models.CharField(max_length=50) + @python_2_unicode_compatible class BaseM(models.Model): base_name = models.CharField(max_length=100) @@ -118,6 +140,7 @@ class BaseM(models.Model): def __str__(self): return self.base_name + @python_2_unicode_compatible class DerivedM(BaseM): customPK = models.IntegerField(primary_key=True) @@ -127,6 +150,7 @@ class DerivedM(BaseM): return "PK = %d, base_name = %s, derived_name = %s" % ( self.customPK, self.base_name, self.derived_name) + class AuditBase(models.Model): planned_date = models.DateField() @@ -134,13 +158,16 @@ class AuditBase(models.Model): abstract = True verbose_name_plural = 'Audits' + class CertificationAudit(AuditBase): class Meta(AuditBase.Meta): abstract = True + class InternalCertificationAudit(CertificationAudit): auditing_dept = models.CharField(max_length=20) + # Check that abstract classes don't get m2m tables autocreated. @python_2_unicode_compatible class Person(models.Model): @@ -152,6 +179,7 @@ class Person(models.Model): def __str__(self): return self.name + @python_2_unicode_compatible class AbstractEvent(models.Model): name = models.CharField(max_length=100) @@ -164,35 +192,44 @@ class AbstractEvent(models.Model): def __str__(self): return self.name + class BirthdayParty(AbstractEvent): pass + class BachelorParty(AbstractEvent): pass + class MessyBachelorParty(BachelorParty): pass + # Check concrete -> abstract -> concrete inheritance class SearchableLocation(models.Model): keywords = models.CharField(max_length=256) + class Station(SearchableLocation): name = models.CharField(max_length=128) class Meta: abstract = True + class BusStation(Station): bus_routes = models.CommaSeparatedIntegerField(max_length=128) inbound = models.BooleanField(default=False) + class TrainStation(Station): zone = models.IntegerField() + class User(models.Model): username = models.CharField(max_length=30, unique=True) + class Profile(User): profile_id = models.AutoField(primary_key=True) extra = models.CharField(max_length=30, blank=True) diff --git a/tests/model_inheritance_select_related/models.py b/tests/model_inheritance_select_related/models.py index 46c67cf07d..81f267589c 100644 --- a/tests/model_inheritance_select_related/models.py +++ b/tests/model_inheritance_select_related/models.py @@ -18,6 +18,7 @@ class Place(models.Model): def __str__(self): return "%s the place" % self.name + @python_2_unicode_compatible class Restaurant(Place): serves_sushi = models.BooleanField(default=False) @@ -26,6 +27,7 @@ class Restaurant(Place): def __str__(self): return "%s the restaurant" % self.name + @python_2_unicode_compatible class Person(models.Model): name = models.CharField(max_length=50) diff --git a/tests/model_validation/models.py b/tests/model_validation/models.py index d2e77cbccc..dfe6d62996 100644 --- a/tests/model_validation/models.py +++ b/tests/model_validation/models.py @@ -39,6 +39,7 @@ class ManyToManyRel(models.Model): # Models created as unmanaged as these aren't ever queried managed = False + class FKRel(models.Model): thing1 = models.ForeignKey(ThingWithIterableChoices, related_name='+') thing2 = models.ForeignKey(ThingWithIterableChoices, related_name='+') diff --git a/tests/modeladmin/models.py b/tests/modeladmin/models.py index 27f54821d6..8f57a9fa82 100644 --- a/tests/modeladmin/models.py +++ b/tests/modeladmin/models.py @@ -16,6 +16,7 @@ class Band(models.Model): def __str__(self): return self.name + class Concert(models.Model): main_band = models.ForeignKey(Band, related_name='main_concerts') opening_band = models.ForeignKey(Band, related_name='opening_concerts', @@ -27,6 +28,7 @@ class Concert(models.Model): (3, 'Bus') ), blank=True) + class ValidationTestModel(models.Model): name = models.CharField(max_length=100) slug = models.SlugField() @@ -40,5 +42,6 @@ class ValidationTestModel(models.Model): def decade_published_in(self): return self.pub_date.strftime('%Y')[:3] + "0's" + class ValidationTestInlineModel(models.Model): parent = models.ForeignKey(ValidationTestModel) diff --git a/tests/multiple_database/models.py b/tests/multiple_database/models.py index 00534c870c..fc5b28ad92 100644 --- a/tests/multiple_database/models.py +++ b/tests/multiple_database/models.py @@ -18,10 +18,12 @@ class Review(models.Model): 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() @@ -33,6 +35,7 @@ class Person(models.Model): 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 @@ -46,6 +49,7 @@ class BookManager(models.Manager): kwargs.pop('extra_arg', None) return super(BookManager, self).get_or_create(*args, **kwargs) + @python_2_unicode_compatible class Book(models.Model): objects = BookManager() @@ -62,6 +66,7 @@ class Book(models.Model): class Meta: ordering = ('title',) + @python_2_unicode_compatible class Pet(models.Model): name = models.CharField(max_length=100) @@ -73,6 +78,7 @@ class Pet(models.Model): class Meta: ordering = ('name',) + class UserProfile(models.Model): user = models.OneToOneField(User, null=True) flavor = models.CharField(max_length=100)