Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing E302 Errors

Signed-off-by: Jason Myers <jason@jasonamyers.com>
  • Loading branch information...
commit c3791463a5a9674f8e0148fbab57eae23c138896 1 parent 2a03a9a
Jason Myers jasonamyers authored
Showing with 748 additions and 96 deletions.
  1. +13 −1 django/forms/widgets.py
  2. +1 −1  setup.cfg
  3. +21 −15 tests/multiple_database/tests.py
  4. +1 −0  tests/mutually_referential/models.py
  5. +2 −0  tests/nested_foreign_keys/models.py
  6. +7 −0 tests/null_fk/models.py
  7. +4 −0 tests/null_fk_ordering/models.py
  8. +5 −0 tests/null_queries/models.py
  9. +7 −2 tests/one_to_one/models.py
  10. +1 −0  tests/one_to_one/tests.py
  11. +2 −0  tests/order_with_respect_to/models.py
  12. +1 −0  tests/ordering/models.py
  13. +5 −0 tests/prefetch_related/models.py
  14. +2 −0  tests/proxy_model_inheritance/models.py
  15. +26 −0 tests/proxy_models/models.py
  16. +91 −0 tests/queries/models.py
  17. +33 −11 tests/queries/tests.py
  18. +6 −0 tests/queryset_pickle/models.py
  19. +4 −0 tests/raw_query/models.py
  20. +1 −0  tests/responses/tests.py
  21. +2 −0  tests/reverse_lookup/models.py
  22. +2 −0  tests/reverse_single_related/models.py
  23. +10 −0 tests/select_related/models.py
  24. +2 −0  tests/select_related_onetoone/models.py
  25. +28 −0 tests/select_related_regress/models.py
  26. +8 −4 tests/serializers/tests.py
  27. +63 −0 tests/serializers_regress/models.py
  28. +36 −12 tests/serializers_regress/tests.py
  29. +1 −0  tests/servers/tests.py
  30. +1 −0  tests/settings_tests/tests.py
  31. +1 −0  tests/signals/models.py
  32. +2 −0  tests/signals/tests.py
  33. +1 −0  tests/signals_regress/models.py
  34. +1 −0  tests/signing/tests.py
  35. +6 −0 tests/sites_framework/models.py
  36. +1 −0  tests/staticfiles_tests/storage.py
  37. +1 −0  tests/str/models.py
  38. +5 −0 tests/string_lookup/models.py
  39. +1 −0  tests/syndication/tests.py
  40. +4 −0 tests/tablespaces/models.py
  41. +2 −0  tests/tablespaces/tests.py
  42. +9 −4 tests/template_tests/filters.py
  43. +2 −0  tests/template_tests/templatetags/bad_tag.py
  44. +49 −0 tests/template_tests/templatetags/custom.py
  45. +1 −0  tests/template_tests/templatetags/subpackage/echo.py
  46. +1 −0  tests/template_tests/test_callables.py
  47. +7 −6 tests/template_tests/test_loaders.py
  48. +2 −1  tests/template_tests/test_nodelist.py
  49. +3 −2 tests/template_tests/test_response.py
  50. +1 −0  tests/template_tests/test_smartif.py
  51. +22 −9 tests/template_tests/tests.py
  52. +5 −0 tests/template_tests/views.py
  53. +3 −1 tests/test_client/tests.py
  54. +22 −0 tests/test_client/views.py
  55. +1 −0  tests/test_client_regress/session.py
  56. +22 −6 tests/test_client_regress/tests.py
  57. +18 −0 tests/test_client_regress/views.py
  58. +1 −0  tests/test_runner/models.py
  59. +1 −0  tests/test_runner_deprecation_app/tests.py
  60. +1 −0  tests/test_utils/models.py
  61. +2 −0  tests/timezones/admin.py
  62. +5 −0 tests/timezones/forms.py
  63. +6 −0 tests/timezones/models.py
  64. +11 −5 tests/transactions/tests.py
  65. +2 −0  tests/transactions_regress/models.py
  66. +4 −1 tests/transactions_regress/tests.py
  67. +12 −1 tests/unmanaged_models/models.py
  68. +4 −0 tests/update/models.py
  69. +1 −0  tests/update_only_fields/models.py
  70. +1 −0  tests/urlpatterns_reverse/erroneous_views_module.py
  71. +5 −0 tests/urlpatterns_reverse/middleware.py
  72. +11 −1 tests/urlpatterns_reverse/tests.py
  73. +1 −0  tests/urlpatterns_reverse/urlconf_inner.py
  74. +10 −0 tests/urlpatterns_reverse/views.py
  75. +1 −0  tests/user_commands/management/commands/leave_locale_alone_false.py
  76. +1 −0  tests/user_commands/management/commands/leave_locale_alone_true.py
  77. +1 −0  tests/utils_tests/test_baseconv.py
  78. +1 −0  tests/utils_tests/test_checksums.py
  79. +1 −0  tests/utils_tests/test_datetime_safe.py
  80. +1 −0  tests/utils_tests/test_decorators.py
  81. +1 −0  tests/utils_tests/test_ipv6.py
  82. +3 −0  tests/utils_tests/test_jslex.py
  83. +5 −0 tests/utils_tests/test_module_loading.py
  84. +1 −0  tests/utils_tests/test_simplelazyobject.py
  85. +1 −0  tests/utils_tests/test_text.py
  86. +5 −4 tests/utils_tests/test_tzinfo.py
  87. +13 −0 tests/validation/models.py
  88. +1 −0  tests/validation/test_unique.py
  89. +2 −1  tests/validation/tests.py
  90. +6 −4 tests/validators/tests.py
  91. +1 −0  tests/version/tests.py
  92. +1 −0  tests/view_tests/__init__.py
  93. +5 −0 tests/view_tests/models.py
  94. +1 −0  tests/view_tests/templatetags/debugtags.py
  95. +5 −4 tests/view_tests/tests/test_debug.py
  96. +1 −0  tests/view_tests/tests/test_shortcuts.py
  97. +32 −0 tests/view_tests/views.py
  98. +1 −0  tests/wsgi/urls.py
14 django/forms/widgets.py
View
@@ -104,6 +104,7 @@ def __add__(self, other):
getattr(combined, 'add_' + name)(getattr(other, '_' + name, None))
return combined
+
def media_property(cls):
def _media(self):
# Get the media property of the superclass, if it exists
@@ -131,6 +132,7 @@ def _media(self):
return base
return property(_media)
+
class MediaDefiningClass(type):
"""
Metaclass for classes that can have media definitions.
@@ -162,6 +164,7 @@ def __str__(self):
args.append(self.choices)
return self.parent_widget.render(*args)
+
class Widget(six.with_metaclass(MediaDefiningClass)):
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
needs_multipart_form = False # Determines does this widget need multipart form
@@ -224,6 +227,7 @@ def id_for_label(self, id_):
"""
return id_
+
class Input(Widget):
"""
Base class for all <input> widgets (except type='checkbox' and
@@ -279,10 +283,12 @@ def render(self, name, value, attrs=None):
value = None
return super(PasswordInput, self).render(name, value, attrs)
+
class HiddenInput(Input):
input_type = 'hidden'
is_hidden = True
+
class MultipleHiddenInput(HiddenInput):
"""
A widget that handles <input type="hidden"> for fields that have a list
@@ -313,6 +319,7 @@ def value_from_datadict(self, data, files, name):
return data.getlist(name)
return data.get(name, None)
+
class FileInput(Input):
input_type = 'file'
needs_multipart_form = True
@@ -327,6 +334,7 @@ def value_from_datadict(self, data, files, name):
FILE_INPUT_CONTRADICTION = object()
+
class ClearableFileInput(FileInput):
initial_text = ugettext_lazy('Currently')
input_text = ugettext_lazy('Change')
@@ -379,7 +387,8 @@ def render(self, name, value, attrs=None):
def value_from_datadict(self, data, files, name):
upload = super(ClearableFileInput, self).value_from_datadict(data, files, name)
if not self.is_required and CheckboxInput().value_from_datadict(
- data, files, self.clear_checkbox_name(name)):
+ data, files, self.clear_checkbox_name(name)):
+
if upload:
# If the user contradicts themselves (uploads a new file AND
# checks the "clear" checkbox), we return a unique marker
@@ -389,6 +398,7 @@ def value_from_datadict(self, data, files, name):
return False
return upload
+
class Textarea(Widget):
def __init__(self, attrs=None):
# The 'rows' and 'cols' attributes are required for HTML correctness.
@@ -515,6 +525,7 @@ def render_options(self, choices, selected_choices):
output.append(self.render_option(selected_choices, option_value, option_label))
return '\n'.join(output)
+
class NullBooleanSelect(Select):
"""
A Select Widget intended to be used with NullBooleanField.
@@ -849,6 +860,7 @@ def decompress(self, value):
return [value.date(), value.time().replace(microsecond=0)]
return [None, None]
+
class SplitHiddenDateTimeWidget(SplitDateTimeWidget):
"""
A Widget that splits datetime input into two <input type="hidden"> inputs.
2  setup.cfg
View
@@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh
[flake8]
exclude=./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./tests/comment_tests/*,./django/test/_doctest.py,./django/utils/six.py,./django/conf/app_template/*
-ignore=E124,E125,E127,E128,E226,E251,E302,E501,E261,W601
+ignore=E124,E125,E127,E128,E226,E251,E501,E261,W601
[metadata]
license-file = LICENSE
36 tests/multiple_database/tests.py
View
@@ -50,7 +50,8 @@ def test_default_creation(self):
except Book.DoesNotExist:
self.fail('"Pro Django" should exist on default database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('other').get,
title="Pro Django"
)
@@ -61,7 +62,8 @@ def test_default_creation(self):
except Book.DoesNotExist:
self.fail('"Dive into Python" should exist on default database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('other').get,
title="Dive into Python"
)
@@ -84,11 +86,13 @@ def test_other_creation(self):
except Book.DoesNotExist:
self.fail('"Pro Django" should exist on other database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.get,
title="Pro Django"
)
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('default').get,
title="Pro Django"
)
@@ -98,11 +102,13 @@ def test_other_creation(self):
except Book.DoesNotExist:
self.fail('"Dive into Python" should exist on other database')
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.get,
title="Dive into Python"
)
- self.assertRaises(Book.DoesNotExist,
+ self.assertRaises(
+ Book.DoesNotExist,
Book.objects.using('default').get,
title="Dive into Python"
)
@@ -164,14 +170,14 @@ def test_m2m_separation(self):
# Check that queries work across m2m joins
self.assertEqual(list(Book.objects.using('default').filter(authors__name='Marty Alchin').values_list('title', flat=True)),
- ['Pro Django'])
+ ['Pro Django'])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Marty Alchin').values_list('title', flat=True)),
- [])
+ [])
self.assertEqual(list(Book.objects.using('default').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- [])
+ [])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
# Reget the objects to clear caches
dive = Book.objects.using('other').get(title="Dive into Python")
@@ -179,10 +185,10 @@ def test_m2m_separation(self):
# Retrive related object by descriptor. Related objects should be database-baound
self.assertEqual(list(dive.authors.all().values_list('name', flat=True)),
- ['Mark Pilgrim'])
+ ['Mark Pilgrim'])
self.assertEqual(list(mark.book_set.all().values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
def test_m2m_forward_operations(self):
"M2M forward manipulations are all constrained to a single DB"
@@ -198,13 +204,13 @@ def test_m2m_forward_operations(self):
# Add a second author
john = Person.objects.using('other').create(name="John Smith")
self.assertEqual(list(Book.objects.using('other').filter(authors__name='John Smith').values_list('title', flat=True)),
- [])
+ [])
dive.authors.add(john)
self.assertEqual(list(Book.objects.using('other').filter(authors__name='Mark Pilgrim').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
self.assertEqual(list(Book.objects.using('other').filter(authors__name='John Smith').values_list('title', flat=True)),
- ['Dive into Python'])
+ ['Dive into Python'])
# Remove the second author
dive.authors.remove(john)
1  tests/mutually_referential/models.py
View
@@ -13,6 +13,7 @@ class Parent(models.Model):
# Use a simple string for forward declarations.
bestchild = models.ForeignKey("Child", null=True, related_name="favoured_by")
+
class Child(models.Model):
name = models.CharField(max_length=100)
2  tests/nested_foreign_keys/models.py
View
@@ -17,6 +17,7 @@ class Event(models.Model):
class Screening(Event):
movie = models.ForeignKey(Movie)
+
class ScreeningNullFK(Event):
movie = models.ForeignKey(Movie, null=True)
@@ -24,5 +25,6 @@ class ScreeningNullFK(Event):
class Package(models.Model):
screening = models.ForeignKey(Screening, null=True)
+
class PackageNullFK(models.Model):
screening = models.ForeignKey(ScreeningNullFK, null=True)
7 tests/null_fk/models.py
View
@@ -9,14 +9,17 @@
class SystemDetails(models.Model):
details = models.TextField()
+
class SystemInfo(models.Model):
system_details = models.ForeignKey(SystemDetails)
system_name = models.CharField(max_length=32)
+
class Forum(models.Model):
system_info = models.ForeignKey(SystemInfo)
forum_name = models.CharField(max_length=32)
+
@python_2_unicode_compatible
class Post(models.Model):
forum = models.ForeignKey(Forum, null=True)
@@ -25,6 +28,7 @@ class Post(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Comment(models.Model):
post = models.ForeignKey(Post, null=True)
@@ -38,12 +42,15 @@ def __str__(self):
# Ticket 15823
+
class Item(models.Model):
title = models.CharField(max_length=100)
+
class PropertyValue(models.Model):
label = models.CharField(max_length=100)
+
class Property(models.Model):
item = models.ForeignKey(Item, related_name='props')
key = models.CharField(max_length=100)
4 tests/null_fk_ordering/models.py
View
@@ -15,6 +15,7 @@
class Author(models.Model):
name = models.CharField(max_length=150)
+
@python_2_unicode_compatible
class Article(models.Model):
title = models.CharField(max_length=150)
@@ -31,10 +32,12 @@ class Meta:
class SystemInfo(models.Model):
system_name = models.CharField(max_length=32)
+
class Forum(models.Model):
system_info = models.ForeignKey(SystemInfo)
forum_name = models.CharField(max_length=32)
+
@python_2_unicode_compatible
class Post(models.Model):
forum = models.ForeignKey(Forum, null=True)
@@ -43,6 +46,7 @@ class Post(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Comment(models.Model):
post = models.ForeignKey(Post, null=True)
5 tests/null_queries/models.py
View
@@ -11,6 +11,7 @@ class Poll(models.Model):
def __str__(self):
return "Q: %s " % self.question
+
@python_2_unicode_compatible
class Choice(models.Model):
poll = models.ForeignKey(Poll)
@@ -20,12 +21,16 @@ def __str__(self):
return "Choice: %s in poll %s" % (self.choice, self.poll)
# A set of models with an inner one pointing to two outer ones.
+
+
class OuterA(models.Model):
pass
+
class OuterB(models.Model):
data = models.CharField(max_length=10)
+
class Inner(models.Model):
first = models.ForeignKey(OuterA)
# second would clash with the __second lookup.
9 tests/one_to_one/models.py
View
@@ -19,6 +19,7 @@ class Place(models.Model):
def __str__(self):
return "%s the place" % self.name
+
@python_2_unicode_compatible
class Restaurant(models.Model):
place = models.OneToOneField(Place, primary_key=True)
@@ -28,6 +29,7 @@ class Restaurant(models.Model):
def __str__(self):
return "%s the restaurant" % self.place.name
+
@python_2_unicode_compatible
class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant)
@@ -36,13 +38,16 @@ class Waiter(models.Model):
def __str__(self):
return "%s the waiter at %s" % (self.name, self.restaurant)
+
class ManualPrimaryKey(models.Model):
primary_key = models.CharField(max_length=10, primary_key=True)
- name = models.CharField(max_length = 50)
+ name = models.CharField(max_length=50)
+
class RelatedModel(models.Model):
link = models.OneToOneField(ManualPrimaryKey)
- name = models.CharField(max_length = 50)
+ name = models.CharField(max_length=50)
+
@python_2_unicode_compatible
class MultiModel(models.Model):
1  tests/one_to_one/tests.py
View
@@ -6,6 +6,7 @@
from .models import (Place, Restaurant, Waiter, ManualPrimaryKey, RelatedModel,
MultiModel)
+
class OneToOneTests(TestCase):
def setUp(self):
2  tests/order_with_respect_to/models.py
View
@@ -10,6 +10,7 @@
class Question(models.Model):
text = models.CharField(max_length=200)
+
@python_2_unicode_compatible
class Answer(models.Model):
text = models.CharField(max_length=200)
@@ -21,6 +22,7 @@ class Meta:
def __str__(self):
return six.text_type(self.text)
+
@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=200)
1  tests/ordering/models.py
View
@@ -28,6 +28,7 @@ class Meta:
def __str__(self):
return self.headline
+
@python_2_unicode_compatible
class ArticlePKOrdering(models.Model):
headline = models.CharField(max_length=100)
5 tests/prefetch_related/models.py
View
@@ -5,6 +5,7 @@
## Basic tests
+
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=50, unique=True)
@@ -55,6 +56,7 @@ def __str__(self):
class Meta:
ordering = ['id']
+
class BookWithYear(Book):
book = models.OneToOneField(Book, parent_link=True)
published_year = models.IntegerField()
@@ -73,12 +75,14 @@ def __str__(self):
class Meta:
ordering = ['id']
+
class BookReview(models.Model):
book = models.ForeignKey(BookWithYear)
notes = models.TextField(null=True, blank=True)
## Models for default manager tests
+
class Qualification(models.Model):
name = models.CharField(max_length=10)
@@ -161,6 +165,7 @@ class House(models.Model):
class Meta:
ordering = ['id']
+
class Room(models.Model):
name = models.CharField(max_length=50)
house = models.ForeignKey(House, related_name='rooms')
2  tests/proxy_model_inheritance/models.py
View
@@ -5,9 +5,11 @@
class ConcreteModel(models.Model):
pass
+
class ConcreteModelSubclass(ConcreteModel):
pass
+
class ConcreteModelSubclassProxy(ConcreteModelSubclass):
class Meta:
proxy = True
26 tests/proxy_models/models.py
View
@@ -9,14 +9,17 @@
# A couple of managers for testing managing overriding in proxy model cases.
+
class PersonManager(models.Manager):
def get_queryset(self):
return super(PersonManager, self).get_queryset().exclude(name="fred")
+
class SubManager(models.Manager):
def get_queryset(self):
return super(SubManager, self).get_queryset().exclude(name="wilma")
+
@python_2_unicode_compatible
class Person(models.Model):
"""
@@ -29,6 +32,7 @@ class Person(models.Model):
def __str__(self):
return self.name
+
class Abstract(models.Model):
"""
A simple abstract base class, to be used for error checking.
@@ -38,6 +42,7 @@ class Abstract(models.Model):
class Meta:
abstract = True
+
class MyPerson(Person):
"""
A proxy subclass, this should not get a new table. Overrides the default
@@ -56,12 +61,14 @@ class Meta:
def has_special_name(self):
return self.name.lower() == "special"
+
class ManagerMixin(models.Model):
excluder = SubManager()
class Meta:
abstract = True
+
class OtherPerson(Person, ManagerMixin):
"""
A class with the default manager from Person, plus an secondary manager.
@@ -70,6 +77,7 @@ class Meta:
proxy = True
ordering = ["name"]
+
class StatusPerson(MyPerson):
"""
A non-proxy subclass of a proxy, it should get a new table.
@@ -77,13 +85,17 @@ class StatusPerson(MyPerson):
status = models.CharField(max_length=80)
# We can even have proxies of proxies (and subclass of those).
+
+
class MyPersonProxy(MyPerson):
class Meta:
proxy = True
+
class LowerStatusPerson(MyPersonProxy):
status = models.CharField(max_length=80)
+
@python_2_unicode_compatible
class User(models.Model):
name = models.CharField(max_length=100)
@@ -91,18 +103,23 @@ class User(models.Model):
def __str__(self):
return self.name
+
class UserProxy(User):
class Meta:
proxy = True
+
class UserProxyProxy(UserProxy):
class Meta:
proxy = True
# We can still use `select_related()` to include related models in our querysets.
+
+
class Country(models.Model):
name = models.CharField(max_length=50)
+
@python_2_unicode_compatible
class State(models.Model):
name = models.CharField(max_length=50)
@@ -111,12 +128,15 @@ class State(models.Model):
def __str__(self):
return self.name
+
class StateProxy(State):
class Meta:
proxy = True
# Proxy models still works with filters (on related fields)
# and select_related, even when mixed with model inheritance
+
+
@python_2_unicode_compatible
class BaseUser(models.Model):
name = models.CharField(max_length=255)
@@ -124,9 +144,11 @@ class BaseUser(models.Model):
def __str__(self):
return ':'.join((self.__class__.__name__, self.name,))
+
class TrackerUser(BaseUser):
status = models.CharField(max_length=50)
+
class ProxyTrackerUser(TrackerUser):
class Meta:
proxy = True
@@ -140,10 +162,12 @@ class Issue(models.Model):
def __str__(self):
return ':'.join((self.__class__.__name__, self.summary,))
+
class Bug(Issue):
version = models.CharField(max_length=50)
reporter = models.ForeignKey(BaseUser)
+
class ProxyBug(Bug):
"""
Proxy of an inherited class
@@ -159,6 +183,7 @@ class ProxyProxyBug(ProxyBug):
class Meta:
proxy = True
+
class Improvement(Issue):
"""
A model that has relation to a proxy model
@@ -168,6 +193,7 @@ class Improvement(Issue):
reporter = models.ForeignKey(ProxyTrackerUser)
associated_bug = models.ForeignKey(ProxyProxyBug)
+
class ProxyImprovement(Improvement):
class Meta:
proxy = True
91 tests/queries/models.py
View
@@ -13,10 +13,12 @@
class DumbCategory(models.Model):
pass
+
class ProxyCategory(DumbCategory):
class Meta:
proxy = True
+
@python_2_unicode_compatible
class NamedCategory(DumbCategory):
name = models.CharField(max_length=10)
@@ -24,6 +26,7 @@ class NamedCategory(DumbCategory):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=10)
@@ -37,6 +40,7 @@ class Meta:
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Note(models.Model):
note = models.CharField(max_length=100)
@@ -55,6 +59,7 @@ def __init__(self, *args, **kwargs):
# that use objects of that type as an argument.
self.lock = threading.Lock()
+
@python_2_unicode_compatible
class Annotation(models.Model):
name = models.CharField(max_length=10)
@@ -64,6 +69,7 @@ class Annotation(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class ExtraInfo(models.Model):
info = models.CharField(max_length=100)
@@ -76,6 +82,7 @@ class Meta:
def __str__(self):
return self.info
+
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=10)
@@ -88,6 +95,7 @@ class Meta:
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Item(models.Model):
name = models.CharField(max_length=10)
@@ -103,6 +111,7 @@ class Meta:
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Report(models.Model):
name = models.CharField(max_length=10)
@@ -111,6 +120,7 @@ class Report(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Ranking(models.Model):
rank = models.IntegerField()
@@ -123,6 +133,7 @@ class Meta:
def __str__(self):
return '%d: %s' % (self.rank, self.author.name)
+
@python_2_unicode_compatible
class Cover(models.Model):
title = models.CharField(max_length=50)
@@ -134,6 +145,7 @@ class Meta:
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Number(models.Model):
num = models.IntegerField()
@@ -143,6 +155,8 @@ def __str__(self):
# Symmetrical m2m field with a normal field using the reverse accesor name
# ("valid").
+
+
class Valid(models.Model):
valid = models.CharField(max_length=10)
parent = models.ManyToManyField('self')
@@ -152,38 +166,49 @@ class Meta:
# Some funky cross-linked models for testing a couple of infinite recursion
# cases.
+
+
class X(models.Model):
y = models.ForeignKey('Y')
+
class Y(models.Model):
x1 = models.ForeignKey(X, related_name='y1')
# Some models with a cycle in the default ordering. This would be bad if we
# didn't catch the infinite loop.
+
+
class LoopX(models.Model):
y = models.ForeignKey('LoopY')
class Meta:
ordering = ['y']
+
class LoopY(models.Model):
x = models.ForeignKey(LoopX)
class Meta:
ordering = ['x']
+
class LoopZ(models.Model):
z = models.ForeignKey('self')
class Meta:
ordering = ['z']
+
# A model and custom default manager combination.
+
+
class CustomManager(models.Manager):
def get_queryset(self):
qs = super(CustomManager, self).get_queryset()
return qs.filter(public=True, tag__name='t1')
+
@python_2_unicode_compatible
class ManagedModel(models.Model):
data = models.CharField(max_length=10)
@@ -197,24 +222,31 @@ def __str__(self):
return self.data
# An inter-related setup with multiple paths from Child to Detail.
+
+
class Detail(models.Model):
data = models.CharField(max_length=10)
+
class MemberManager(models.Manager):
def get_queryset(self):
return super(MemberManager, self).get_queryset().select_related("details")
+
class Member(models.Model):
name = models.CharField(max_length=10)
details = models.OneToOneField(Detail, primary_key=True)
objects = MemberManager()
+
class Child(models.Model):
person = models.OneToOneField(Member, primary_key=True)
parent = models.ForeignKey(Member, related_name="children")
# Custom primary keys interfered with ordering in the past.
+
+
class CustomPk(models.Model):
name = models.CharField(max_length=10, primary_key=True)
extra = models.CharField(max_length=10)
@@ -222,12 +254,14 @@ class CustomPk(models.Model):
class Meta:
ordering = ['name', 'extra']
+
class Related(models.Model):
custom = models.ForeignKey(CustomPk)
# An inter-related setup with a model subclass that has a nullable
# path to another model, and a return path from that model.
+
@python_2_unicode_compatible
class Celebrity(models.Model):
name = models.CharField("Name", max_length=20)
@@ -236,13 +270,17 @@ class Celebrity(models.Model):
def __str__(self):
return self.name
+
class TvChef(Celebrity):
pass
+
class Fan(models.Model):
fan_of = models.ForeignKey(Celebrity)
# Multiple foreign keys
+
+
@python_2_unicode_compatible
class LeafA(models.Model):
data = models.CharField(max_length=10)
@@ -250,13 +288,16 @@ class LeafA(models.Model):
def __str__(self):
return self.data
+
class LeafB(models.Model):
data = models.CharField(max_length=10)
+
class Join(models.Model):
a = models.ForeignKey(LeafA)
b = models.ForeignKey(LeafB)
+
@python_2_unicode_compatible
class ReservedName(models.Model):
name = models.CharField(max_length=20)
@@ -266,6 +307,8 @@ def __str__(self):
return self.name
# A simpler shared-foreign-key setup that can expose some problems.
+
+
@python_2_unicode_compatible
class SharedConnection(models.Model):
data = models.CharField(max_length=10)
@@ -273,13 +316,17 @@ class SharedConnection(models.Model):
def __str__(self):
return self.data
+
class PointerA(models.Model):
connection = models.ForeignKey(SharedConnection)
+
class PointerB(models.Model):
connection = models.ForeignKey(SharedConnection)
# Multi-layer ordering
+
+
@python_2_unicode_compatible
class SingleObject(models.Model):
name = models.CharField(max_length=10)
@@ -290,6 +337,7 @@ class Meta:
def __str__(self):
return self.name
+
class RelatedObject(models.Model):
single = models.ForeignKey(SingleObject, null=True)
f = models.IntegerField(null=True)
@@ -297,6 +345,7 @@ class RelatedObject(models.Model):
class Meta:
ordering = ['single']
+
@python_2_unicode_compatible
class Plaything(models.Model):
name = models.CharField(max_length=10)
@@ -308,10 +357,12 @@ class Meta:
def __str__(self):
return self.name
+
class Article(models.Model):
name = models.CharField(max_length=20)
created = models.DateTimeField()
+
@python_2_unicode_compatible
class Food(models.Model):
name = models.CharField(max_length=20, unique=True)
@@ -319,6 +370,7 @@ class Food(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Eaten(models.Model):
food = models.ForeignKey(Food, to_field="name", null=True)
@@ -327,6 +379,7 @@ class Eaten(models.Model):
def __str__(self):
return "%s at %s" % (self.food, self.meal)
+
@python_2_unicode_compatible
class Node(models.Model):
num = models.IntegerField(unique=True)
@@ -336,6 +389,8 @@ def __str__(self):
return "%s" % self.num
# Bug #12252
+
+
@python_2_unicode_compatible
class ObjectA(models.Model):
name = models.CharField(max_length=50)
@@ -343,6 +398,7 @@ class ObjectA(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class ObjectB(models.Model):
name = models.CharField(max_length=50)
@@ -352,6 +408,7 @@ class ObjectB(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class ObjectC(models.Model):
name = models.CharField(max_length=50)
@@ -361,6 +418,7 @@ class ObjectC(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class SimpleCategory(models.Model):
name = models.CharField(max_length=15)
@@ -368,6 +426,7 @@ class SimpleCategory(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class SpecialCategory(SimpleCategory):
special_name = models.CharField(max_length=15)
@@ -375,6 +434,7 @@ class SpecialCategory(SimpleCategory):
def __str__(self):
return self.name + " " + self.special_name
+
@python_2_unicode_compatible
class CategoryItem(models.Model):
category = models.ForeignKey(SimpleCategory)
@@ -382,6 +442,7 @@ class CategoryItem(models.Model):
def __str__(self):
return "category item: " + str(self.category)
+
@python_2_unicode_compatible
class OneToOneCategory(models.Model):
new_name = models.CharField(max_length=15)
@@ -390,31 +451,38 @@ class OneToOneCategory(models.Model):
def __str__(self):
return "one2one " + self.new_name
+
class CategoryRelationship(models.Model):
first = models.ForeignKey(SimpleCategory, related_name='first_rel')
second = models.ForeignKey(SimpleCategory, related_name='second_rel')
+
class NullableName(models.Model):
name = models.CharField(max_length=20, null=True)
class Meta:
ordering = ['id']
+
class ModelD(models.Model):
name = models.TextField()
+
class ModelC(models.Model):
name = models.TextField()
+
class ModelB(models.Model):
name = models.TextField()
c = models.ForeignKey(ModelC)
+
class ModelA(models.Model):
name = models.TextField()
b = models.ForeignKey(ModelB, null=True)
d = models.ForeignKey(ModelD)
+
@python_2_unicode_compatible
class Job(models.Model):
name = models.CharField(max_length=20, unique=True)
@@ -422,10 +490,12 @@ class Job(models.Model):
def __str__(self):
return self.name
+
class JobResponsibilities(models.Model):
job = models.ForeignKey(Job, to_field='name')
responsibility = models.ForeignKey('Responsibility', to_field='description')
+
@python_2_unicode_compatible
class Responsibility(models.Model):
description = models.CharField(max_length=20, unique=True)
@@ -436,23 +506,29 @@ def __str__(self):
return self.description
# Models for disjunction join promotion low level testing.
+
+
class FK1(models.Model):
f1 = models.TextField()
f2 = models.TextField()
+
class FK2(models.Model):
f1 = models.TextField()
f2 = models.TextField()
+
class FK3(models.Model):
f1 = models.TextField()
f2 = models.TextField()
+
class BaseA(models.Model):
a = models.ForeignKey(FK1, null=True)
b = models.ForeignKey(FK2, null=True)
c = models.ForeignKey(FK3, null=True)
+
@python_2_unicode_compatible
class Identifier(models.Model):
name = models.CharField(max_length=100)
@@ -460,17 +536,21 @@ class Identifier(models.Model):
def __str__(self):
return self.name
+
class Program(models.Model):
identifier = models.OneToOneField(Identifier)
+
class Channel(models.Model):
programs = models.ManyToManyField(Program)
identifier = models.OneToOneField(Identifier)
+
class Book(models.Model):
title = models.TextField()
chapter = models.ForeignKey('Chapter')
+
class Chapter(models.Model):
title = models.TextField()
paragraph = models.ForeignKey('Paragraph')
@@ -480,15 +560,19 @@ class Paragraph(models.Model):
text = models.TextField()
page = models.ManyToManyField('Page')
+
class Page(models.Model):
text = models.TextField()
+
class MyObject(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
data = models.CharField(max_length=100)
created_at = models.DateTimeField(auto_now_add=True)
# Models for #17600 regressions
+
+
@python_2_unicode_compatible
class Order(models.Model):
id = models.IntegerField(primary_key=True)
@@ -499,6 +583,7 @@ class Meta:
def __str__(self):
return '%s' % self.pk
+
@python_2_unicode_compatible
class OrderItem(models.Model):
order = models.ForeignKey(Order, related_name='items')
@@ -510,9 +595,11 @@ class Meta:
def __str__(self):
return '%s' % self.pk
+
class BaseUser(models.Model):
pass
+
@python_2_unicode_compatible
class Task(models.Model):
title = models.CharField(max_length=10)
@@ -522,6 +609,7 @@ class Task(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class Staff(models.Model):
name = models.CharField(max_length=10)
@@ -529,6 +617,7 @@ class Staff(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class StaffUser(BaseUser):
staff = models.OneToOneField(Staff, related_name='user')
@@ -536,11 +625,13 @@ class StaffUser(BaseUser):
def __str__(self):
return self.staff
+
class Ticket21203Parent(models.Model):
parentid = models.AutoField(primary_key=True)
parent_bool = models.BooleanField(default=True)
created = models.DateTimeField(auto_now=True)
+
class Ticket21203Child(models.Model):
childid = models.AutoField(primary_key=True)
parent = models.ForeignKey(Ticket21203Parent)
44 tests/queries/tests.py
View
@@ -28,6 +28,7 @@
CategoryRelationship, Ticket21203Parent, Ticket21203Child, Person,
Company, Employment)
+
class BaseQuerysetTest(TestCase):
def assertValueQuerysetEqual(self, qs, values):
return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
@@ -827,7 +828,7 @@ def test_ticket9411(self):
qs = Tag.objects.values_list('id', flat=True).order_by('id')
qs.query.bump_prefix(qs.query)
first = qs[0]
- self.assertEqual(list(qs), list(range(first, first+5)))
+ self.assertEqual(list(qs), list(range(first, first + 5)))
def test_ticket8439(self):
# Complex combinations of conjunctions, disjunctions and nullable
@@ -1262,6 +1263,7 @@ def test_ticket8683(self):
Item.objects.datetimes, 'name', 'month'
)
+
class Queries4Tests(BaseQuerysetTest):
def setUp(self):
generic = NamedCategory.objects.create(name="Generic")
@@ -1445,8 +1447,8 @@ def test_ticket15316_one2one_filter_false(self):
c0 = SimpleCategory.objects.create(name="cat0")
c1 = SimpleCategory.objects.create(name="category1")
- OneToOneCategory.objects.create(category = c1, new_name="new1")
- OneToOneCategory.objects.create(category = c0, new_name="new2")
+ OneToOneCategory.objects.create(category=c1, new_name="new1")
+ OneToOneCategory.objects.create(category=c0, new_name="new2")
CategoryItem.objects.create(category=c)
ci2 = CategoryItem.objects.create(category=c0)
@@ -1461,8 +1463,8 @@ def test_ticket15316_one2one_exclude_false(self):
c0 = SimpleCategory.objects.create(name="cat0")
c1 = SimpleCategory.objects.create(name="category1")
- OneToOneCategory.objects.create(category = c1, new_name="new1")
- OneToOneCategory.objects.create(category = c0, new_name="new2")
+ OneToOneCategory.objects.create(category=c1, new_name="new1")
+ OneToOneCategory.objects.create(category=c0, new_name="new2")
ci1 = CategoryItem.objects.create(category=c)
CategoryItem.objects.create(category=c0)
@@ -1477,8 +1479,8 @@ def test_ticket15316_one2one_filter_true(self):
c0 = SimpleCategory.objects.create(name="cat0")
c1 = SimpleCategory.objects.create(name="category1")
- OneToOneCategory.objects.create(category = c1, new_name="new1")
- OneToOneCategory.objects.create(category = c0, new_name="new2")
+ OneToOneCategory.objects.create(category=c1, new_name="new1")
+ OneToOneCategory.objects.create(category=c0, new_name="new2")
ci1 = CategoryItem.objects.create(category=c)
CategoryItem.objects.create(category=c0)
@@ -1493,8 +1495,8 @@ def test_ticket15316_one2one_exclude_true(self):
c0 = SimpleCategory.objects.create(name="cat0")
c1 = SimpleCategory.objects.create(name="category1")
- OneToOneCategory.objects.create(category = c1, new_name="new1")
- OneToOneCategory.objects.create(category = c0, new_name="new2")
+ OneToOneCategory.objects.create(category=c1, new_name="new1")
+ OneToOneCategory.objects.create(category=c0, new_name="new2")
CategoryItem.objects.create(category=c)
ci2 = CategoryItem.objects.create(category=c0)
@@ -2019,6 +2021,7 @@ def test_no_fields_cloning(self):
else:
opts_class.__deepcopy__ = note_deepcopy
+
class EmptyQuerySetTests(TestCase):
def test_emptyqueryset_values(self):
# #14366 -- Calling .values() on an empty QuerySet and then cloning
@@ -2224,12 +2227,12 @@ def test_infinite_loop(self):
self.assertRaisesMessage(
FieldError,
'Infinite loop caused by ordering.',
- lambda: list(LoopX.objects.all()) # Force queryset evaluation with list()
+ lambda: list(LoopX.objects.all()) # Force queryset evaluation with list()
)
self.assertRaisesMessage(
FieldError,
'Infinite loop caused by ordering.',
- lambda: list(LoopZ.objects.all()) # Force queryset evaluation with list()
+ lambda: list(LoopZ.objects.all()) # Force queryset evaluation with list()
)
# Note that this doesn't cause an infinite loop, since the default
@@ -2353,6 +2356,7 @@ def test_no_extra_params(self):
except TypeError:
self.fail("Creation of an instance of a model with only the PK field shouldn't error out after bulk insert refactoring (#17056)")
+
class ExcludeTests(TestCase):
def setUp(self):
f1 = Food.objects.create(name='apples')
@@ -2504,6 +2508,7 @@ def test_only_orders_with_all_items_having_status_1(self):
Order.objects.exclude(~Q(items__status=1)).distinct(),
['<Order: 1>'])
+
class Exclude15786(TestCase):
"""Regression test for #15786"""
def test_ticket15786(self):
@@ -2562,6 +2567,7 @@ def test_double_exclude(self):
'IS NOT NULL',
str(NullableName.objects.filter(~~Q(name='i1')).query))
+
class EmptyStringsAsNullTest(TestCase):
"""
Test that filtering on non-null character fields works as expected.
@@ -2591,6 +2597,7 @@ def test_21001(self):
[foo.pk], attrgetter('pk')
)
+
class ProxyQueryCleanupTest(TestCase):
def test_evaluated_proxy_count(self):
"""
@@ -2603,6 +2610,7 @@ def test_evaluated_proxy_count(self):
str(qs.query)
self.assertEqual(qs.count(), 1)
+
class WhereNodeTest(TestCase):
class DummyNode(object):
def as_sql(self, qn, connection):
@@ -2768,6 +2776,7 @@ def test_ticket_21366(self):
self.assertQuerysetEqual(
qs.order_by('name'), [r2, r1], lambda x: x)
+
class ReverseJoinTrimmingTest(TestCase):
def test_reverse_trimming(self):
# Check that we don't accidentally trim reverse joins - we can't know
@@ -2778,6 +2787,7 @@ def test_reverse_trimming(self):
self.assertIn('INNER JOIN', str(qs.query))
self.assertEqual(list(qs), [])
+
class JoinReuseTest(TestCase):
"""
Test that the queries reuse joins sensibly (for example, direct joins
@@ -2811,6 +2821,7 @@ def test_revfk_noreuse(self):
qs = Author.objects.filter(report__name='r4').filter(report__name='r1')
self.assertEqual(str(qs.query).count('JOIN'), 2)
+
class DisjunctionPromotionTests(TestCase):
def test_disjuction_promotion_select_related(self):
fk1 = FK1.objects.create(f1='f1', f2='f2')
@@ -2986,6 +2997,7 @@ def test_ticket_12823(self):
self.assertIn(b2, q)
self.assertIn(b3, q)
+
class RelabelCloneTest(TestCase):
def test_ticket_19964(self):
my1 = MyObject.objects.create(data='foo')
@@ -3000,6 +3012,7 @@ def test_ticket_19964(self):
self.assertEqual(list(children), [my2])
self.assertEqual(list(parents), [my1])
+
class Ticket20101Tests(TestCase):
def test_ticket_20101(self):
"""
@@ -3016,6 +3029,7 @@ def test_ticket_20101(self):
self.assertFalse(n in qs2)
self.assertTrue(n in (qs1 | qs2))
+
class EmptyStringPromotionTests(TestCase):
def test_empty_string_promotion(self):
qs = RelatedObject.objects.filter(single__name='')
@@ -3024,6 +3038,7 @@ def test_empty_string_promotion(self):
else:
self.assertNotIn('LEFT OUTER JOIN', str(qs.query))
+
class ValuesSubqueryTests(TestCase):
def test_values_in_subquery(self):
# Check that if a values() queryset is used, then the given values
@@ -3041,6 +3056,7 @@ def test_values_in_subquery(self):
Order.objects.filter(items__in=OrderItem.objects.values_list('status')),
[o1.pk], lambda x: x.pk)
+
class DoubleInSubqueryTests(TestCase):
def test_double_subquery_in(self):
lfa1 = LeafA.objects.create(data='foo')
@@ -3055,6 +3071,7 @@ def test_double_subquery_in(self):
self.assertQuerysetEqual(
qs, [lfb1], lambda x: x)
+
class Ticket18785Tests(TestCase):
def test_ticket_18785(self):
# Test join trimming from ticket18785
@@ -3085,6 +3102,7 @@ def test_ticket_20788(self):
self.assertQuerysetEqual(
sentences_not_in_pub, [book2], lambda x: x)
+
class Ticket12807Tests(TestCase):
def test_ticket_12807(self):
p1 = Paragraph.objects.create()
@@ -3111,6 +3129,7 @@ def test_wrong_type_lookup(self):
ObjectB.objects.filter(objecta__in=[wrong_type]),
[ob], lambda x: x)
+
class Ticket14056Tests(TestCase):
def test_ticket_14056(self):
s1 = SharedConnection.objects.create(data='s1')
@@ -3126,6 +3145,7 @@ def test_ticket_14056(self):
expected_ordering, lambda x: x
)
+
class Ticket20955Tests(TestCase):
def test_ticket_20955(self):
jack = Staff.objects.create(name='jackstaff')
@@ -3146,6 +3166,7 @@ def test_ticket_20955(self):
self.assertEqual(task_select_related.owner.staffuser.staff,
task_get.owner.staffuser.staff)
+
class Ticket21203Tests(TestCase):
def test_ticket_21203(self):
p = Ticket21203Parent.objects.create(parent_bool=True)
@@ -3154,6 +3175,7 @@ def test_ticket_21203(self):
self.assertQuerysetEqual(qs, [c], lambda x: x)
self.assertIs(qs[0].parent.parent_bool, True)
+
class ValuesJoinPromotionTests(TestCase):
def test_values_no_promotion_for_existing(self):
qs = Node.objects.filter(parent__parent__isnull=False)
6 tests/queryset_pickle/models.py
View
@@ -7,6 +7,7 @@
def standalone_number():
return 1
+
class Numbers(object):
@staticmethod
def get_static_number():
@@ -21,12 +22,15 @@ def get_member_number(self):
nn = Numbers()
+
class Group(models.Model):
name = models.CharField(_('name'), max_length=100)
+
class Event(models.Model):
group = models.ForeignKey(Group)
+
class Happening(models.Model):
when = models.DateTimeField(blank=True, default=datetime.datetime.now)
name = models.CharField(blank=True, max_length=100, default=lambda: "test")
@@ -35,6 +39,7 @@ class Happening(models.Model):
number3 = models.IntegerField(blank=True, default=Numbers.get_class_number)
number4 = models.IntegerField(blank=True, default=nn.get_member_number)
+
class Container(object):
# To test pickling we need a class that isn't defined on module, but
# is still available from app-cache. So, the Container class moves
@@ -42,5 +47,6 @@ class Container(object):
class SomeModel(models.Model):
somefield = models.IntegerField()
+
class M2MModel(models.Model):
groups = models.ManyToManyField(Group)
4 tests/raw_query/models.py
View
@@ -15,17 +15,21 @@ def __init__(self, *args, **kwargs):
assert k in [f.attname for f in self._meta.fields], \
"Author.__init__ got an unexpected parameter: %s" % k
+
class Book(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey(Author)
paperback = models.BooleanField(default=False)
opening_line = models.TextField()
+
class Coffee(models.Model):
brand = models.CharField(max_length=255, db_column="name")
+
class Reviewer(models.Model):
reviewed = models.ManyToManyField(Book)
+
class FriendlyAuthor(Author):
pass
1  tests/responses/tests.py
View
@@ -1,6 +1,7 @@
from django.http import HttpResponse
import unittest
+
class HttpResponseTests(unittest.TestCase):
def test_status_code(self):
2  tests/reverse_lookup/models.py
View
@@ -15,6 +15,7 @@ class User(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Poll(models.Model):
question = models.CharField(max_length=200)
@@ -23,6 +24,7 @@ class Poll(models.Model):
def __str__(self):
return self.question
+
@python_2_unicode_compatible
class Choice(models.Model):
name = models.CharField(max_length=100)
2  tests/reverse_single_related/models.py
View
@@ -5,9 +5,11 @@ class SourceManager(models.Manager):
def get_queryset(self):
return super(SourceManager, self).get_queryset().filter(is_public=True)
+
class Source(models.Model):
is_public = models.BooleanField(default=False)
objects = SourceManager()
+
class Item(models.Model):
source = models.ForeignKey(Source)
10 tests/select_related/models.py
View
@@ -12,6 +12,7 @@
# Who remembers high school biology?
+
@python_2_unicode_compatible
class Domain(models.Model):
name = models.CharField(max_length=50)
@@ -19,6 +20,7 @@ class Domain(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Kingdom(models.Model):
name = models.CharField(max_length=50)
@@ -27,6 +29,7 @@ class Kingdom(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Phylum(models.Model):
name = models.CharField(max_length=50)
@@ -35,6 +38,7 @@ class Phylum(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Klass(models.Model):
name = models.CharField(max_length=50)
@@ -43,6 +47,7 @@ class Klass(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Order(models.Model):
name = models.CharField(max_length=50)
@@ -51,6 +56,7 @@ class Order(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Family(models.Model):
name = models.CharField(max_length=50)
@@ -59,6 +65,7 @@ class Family(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Genus(models.Model):
name = models.CharField(max_length=50)
@@ -67,6 +74,7 @@ class Genus(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Species(models.Model):
name = models.CharField(max_length=50)
@@ -76,6 +84,8 @@ def __str__(self):
return self.name
# and we'll invent a new thing so we have a model with two foreign keys
+
+
@python_2_unicode_compatible
class HybridSpecies(models.Model):
name = models.CharField(max_length=50)
2  tests/select_related_onetoone/models.py
View
@@ -95,8 +95,10 @@ class Child2(Parent1):
def __str__(self):
return self.name1
+
class Child3(Child2):
value3 = models.IntegerField()
+
class Child4(Child1):
value4 = models.IntegerField()
28 tests/select_related_regress/models.py
View
@@ -11,6 +11,7 @@ class Building(models.Model):
def __str__(self):
return "Building: %s" % self.name
+
@python_2_unicode_compatible
class Device(models.Model):
building = models.ForeignKey('Building')
@@ -19,6 +20,7 @@ class Device(models.Model):
def __str__(self):
return "device '%s' in building %s" % (self.name, self.building)
+
@python_2_unicode_compatible
class Port(models.Model):
device = models.ForeignKey('Device')
@@ -27,6 +29,7 @@ class Port(models.Model):
def __str__(self):
return "%s/%s" % (self.device.name, self.port_number)
+
@python_2_unicode_compatible
class Connection(models.Model):
start = models.ForeignKey(Port, related_name='connection_start',
@@ -38,45 +41,60 @@ def __str__(self):
# Another non-tree hierarchy that exercises code paths similar to the above
# example, but in a slightly different configuration.
+
+
class TUser(models.Model):
name = models.CharField(max_length=200)
+
class Person(models.Model):
user = models.ForeignKey(TUser, unique=True)
+
class Organizer(models.Model):
person = models.ForeignKey(Person)
+
class Student(models.Model):
person = models.ForeignKey(Person)
+
class Class(models.Model):
org = models.ForeignKey(Organizer)
+
class Enrollment(models.Model):
std = models.ForeignKey(Student)
cls = models.ForeignKey(Class)
# Models for testing bug #8036.
+
+
class Country(models.Model):
name = models.CharField(max_length=50)
+
class State(models.Model):
name = models.CharField(max_length=50)
country = models.ForeignKey(Country)
+
class ClientStatus(models.Model):
name = models.CharField(max_length=50)
+
class Client(models.Model):
name = models.CharField(max_length=50)
state = models.ForeignKey(State, null=True)
status = models.ForeignKey(ClientStatus)
+
class SpecialClient(Client):
value = models.IntegerField()
# Some model inheritance exercises
+
+
@python_2_unicode_compatible
class Parent(models.Model):
name = models.CharField(max_length=10)
@@ -84,9 +102,11 @@ class Parent(models.Model):
def __str__(self):
return self.name
+
class Child(Parent):
value = models.IntegerField()
+
@python_2_unicode_compatible
class Item(models.Model):
name = models.CharField(max_length=10)
@@ -96,6 +116,8 @@ def __str__(self):
return self.name
# Models for testing bug #19870.
+
+
@python_2_unicode_compatible
class Fowl(models.Model):
name = models.CharField(max_length=10)
@@ -103,12 +125,15 @@ class Fowl(models.Model):
def __str__(self):
return self.name
+
class Hen(Fowl):
pass
+
class Chick(Fowl):
mother = models.ForeignKey(Hen)
+
class Base(models.Model):
name = models.CharField(max_length=10)
lots_of_text = models.TextField()
@@ -116,12 +141,15 @@ class Base(models.Model):
class Meta:
abstract = True
+
class A(Base):
a_field = models.CharField(max_length=10)
+
class B(Base):
b_field = models.CharField(max_length=10)
+
class C(Base):
c_a = models.ForeignKey(A)
c_b = models.ForeignKey(B)
12 tests/serializers/tests.py
View
@@ -26,7 +26,7 @@
@override_settings(
- SERIALIZATION_MODULES = {
+ SERIALIZATION_MODULES={
"json2": "django.core.serializers.json",
}
)
@@ -71,6 +71,7 @@ def test_builtin_serializers(self):
self.assertIn('python', all_formats)
self.assertNotIn('python', public_formats)
+
class SerializersTestBase(object):
@staticmethod
def _comparison_value(value):
@@ -241,9 +242,9 @@ def test_pre_1000ad_date(self):
# Regression for #12524 -- dates before 1000AD get prefixed
# 0's on the year
a = Article.objects.create(
- author = self.jane,
- headline = "Nobody remembers the early years",
- pub_date = datetime(1, 2, 3, 4, 5, 6))
+ author=self.jane,
+ headline="Nobody remembers the early years",
+ pub_date=datetime(1, 2, 3, 4, 5, 6))
serial_str = serializers.serialize(self.serializer_name, [a])
date_values = self._get_field_values(serial_str, "pub_date")
@@ -338,6 +339,7 @@ def _get_field_values(serial_str, field_name):
ret_list.append("".join(temp))
return ret_list
+
class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
serializer_name = "xml"
fwd_ref_str = """<?xml version="1.0" encoding="utf-8"?>
@@ -438,6 +440,8 @@ class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact
YAML_IMPORT_ERROR_MESSAGE = r'No module named yaml'
+
+
class YamlImportModuleMock(object):
"""Provides a wrapped import_module function to simulate yaml ImportError
63 tests/serializers_regress/models.py
View
@@ -13,74 +13,96 @@
# The following classes are for testing basic data
# marshalling, including NULL values, where allowed.
+
class BinaryData(models.Model):
data = models.BinaryField(null=True)
+
class BooleanData(models.Model):
data = models.BooleanField(default=False)
+
class CharData(models.Model):
data = models.CharField(max_length=30, null=True)
+
class DateData(models.Model):
data = models.DateField(null=True)
+
class DateTimeData(models.Model):
data = models.DateTimeField(null=True)
+
class DecimalData(models.Model):
data = models.DecimalField(null=True, decimal_places=3, max_digits=5)
+
class EmailData(models.Model):
data = models.EmailField(null=True)
+
class FileData(models.Model):
data = models.FileField(null=True, upload_to='/foo/bar')
+
class FilePathData(models.Model):
data = models.FilePathField(null=True)
+
class FloatData(models.Model):
data = models.FloatField(null=True)
+
class IntegerData(models.Model):
data = models.IntegerField(null=True)
+
class BigIntegerData(models.Model):
data = models.BigIntegerField(null=True)
# class ImageData(models.Model):
# data = models.ImageField(null=True)
+
class IPAddressData(models.Model):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
data = models.IPAddressField(null=True)
+
class GenericIPAddressData(models.Model):
data = models.GenericIPAddressField(null=True)
+
class NullBooleanData(models.Model):
data = models.NullBooleanField(null=True)
+
class PositiveIntegerData(models.Model):
data = models.PositiveIntegerField(null=True)
+
class PositiveSmallIntegerData(models.Model):
data = models.PositiveSmallIntegerField(null=True)
+
class SlugData(models.Model):
data = models.SlugField(null=True)
+
class SmallData(models.Model):
data = models.SmallIntegerField(null=True)
+
class TextData(models.Model):
data = models.TextField(null=True)
+
class TimeData(models.Model):
data = models.TimeField(null=True)
+
class Tag(models.Model):
"""A tag on an item."""
data = models.SlugField()
@@ -92,6 +114,7 @@ class Tag(models.Model):
class Meta:
ordering = ["data"]
+
class GenericData(models.Model):
data = models.CharField(max_length=30)
@@ -101,6 +124,7 @@ class GenericData(models.Model):
# of related objects; in particular, forward, backward,
# and self references.
+
class Anchor(models.Model):
"""This is a model that can be used as
something for other models to point at"""
@@ -110,10 +134,12 @@ class Anchor(models.Model):
class Meta:
ordering = ('id',)
+
class NaturalKeyAnchorManager(models.Manager):
def get_by_natural_key(self, data):
return self.get(data=data)
+
class NaturalKeyAnchor(models.Model):
objects = NaturalKeyAnchorManager()