mirror of
https://github.com/django/django.git
synced 2024-12-27 11:35:53 +00:00
d4a0b27838
* Renamed the __unicode__ methods * Applied the python_2_unicode_compatible decorator * Removed the StrAndUnicode mix-in that is superseded by python_2_unicode_compatible * Kept the __unicode__ methods in classes that specifically test it under Python 2
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
"""
|
|
Regression tests for custom manager classes.
|
|
"""
|
|
|
|
from django.db import models
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
|
|
class RestrictedManager(models.Manager):
|
|
"""
|
|
A manager that filters out non-public instances.
|
|
"""
|
|
def get_query_set(self):
|
|
return super(RestrictedManager, self).get_query_set().filter(is_public=True)
|
|
|
|
@python_2_unicode_compatible
|
|
class RelatedModel(models.Model):
|
|
name = models.CharField(max_length=50)
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
@python_2_unicode_compatible
|
|
class RestrictedModel(models.Model):
|
|
name = models.CharField(max_length=50)
|
|
is_public = models.BooleanField(default=False)
|
|
related = models.ForeignKey(RelatedModel)
|
|
|
|
objects = RestrictedManager()
|
|
plain_manager = models.Manager()
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
@python_2_unicode_compatible
|
|
class OneToOneRestrictedModel(models.Model):
|
|
name = models.CharField(max_length=50)
|
|
is_public = models.BooleanField(default=False)
|
|
related = models.OneToOneField(RelatedModel)
|
|
|
|
objects = RestrictedManager()
|
|
plain_manager = models.Manager()
|
|
|
|
def __str__(self):
|
|
return self.name
|