diff options
author | django-bot <ops@djangoproject.com> | 2022-02-03 20:24:19 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-07 20:37:05 +0100 |
commit | 9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch) | |
tree | f0506b668a013d0063e5fba3dbf4863b466713ba /tests/proxy_models/models.py | |
parent | f68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff) | |
download | django-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz |
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/proxy_models/models.py')
-rw-r--r-- | tests/proxy_models/models.py | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/tests/proxy_models/models.py b/tests/proxy_models/models.py index 5e6fdd2b93..604136b5ac 100644 --- a/tests/proxy_models/models.py +++ b/tests/proxy_models/models.py @@ -23,6 +23,7 @@ class Person(models.Model): """ A simple concrete base class. """ + name = models.CharField(max_length=50) objects = PersonManager() @@ -35,6 +36,7 @@ class Abstract(models.Model): """ A simple abstract base class, to be used for error checking. """ + data = models.CharField(max_length=10) class Meta: @@ -46,12 +48,11 @@ class MyPerson(Person): A proxy subclass, this should not get a new table. Overrides the default manager. """ + class Meta: proxy = True ordering = ["name"] - permissions = ( - ("display_users", "May display users information"), - ) + permissions = (("display_users", "May display users information"),) objects = SubManager() other = PersonManager() @@ -71,6 +72,7 @@ class OtherPerson(Person, ManagerMixin): """ A class with the default manager from Person, plus a secondary manager. """ + class Meta: proxy = True ordering = ["name"] @@ -80,10 +82,12 @@ class StatusPerson(MyPerson): """ A non-proxy subclass of a proxy, it should get a new table. """ + status = models.CharField(max_length=80) objects = models.Manager() + # We can even have proxies of proxies (and subclass of those). @@ -124,6 +128,7 @@ class MultiUserProxy(UserProxy, AnotherUserProxy): class Meta: proxy = True + # We can still use `select_related()` to include related models in our querysets. @@ -143,6 +148,7 @@ 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 @@ -151,7 +157,12 @@ class BaseUser(models.Model): name = models.CharField(max_length=255) def __str__(self): - return ':'.join((self.__class__.__name__, self.name,)) + return ":".join( + ( + self.__class__.__name__, + self.name, + ) + ) class TrackerUser(BaseUser): @@ -165,10 +176,17 @@ class ProxyTrackerUser(TrackerUser): class Issue(models.Model): summary = models.CharField(max_length=255) - assignee = models.ForeignKey(ProxyTrackerUser, models.CASCADE, related_name='issues') + assignee = models.ForeignKey( + ProxyTrackerUser, models.CASCADE, related_name="issues" + ) def __str__(self): - return ':'.join((self.__class__.__name__, self.summary,)) + return ":".join( + ( + self.__class__.__name__, + self.summary, + ) + ) class Bug(Issue): @@ -180,6 +198,7 @@ class ProxyBug(Bug): """ Proxy of an inherited class """ + class Meta: proxy = True @@ -188,6 +207,7 @@ class ProxyProxyBug(ProxyBug): """ A proxy of proxy model with related field """ + class Meta: proxy = True @@ -197,6 +217,7 @@ class Improvement(Issue): A model that has relation to a proxy model or to a proxy of proxy model """ + version = models.CharField(max_length=50) reporter = models.ForeignKey(ProxyTrackerUser, models.CASCADE) associated_bug = models.ForeignKey(ProxyProxyBug, models.CASCADE) |