mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #19069 -- Improved the error message when trying to query a swapped model.
Thanks to Preston Holmes for the suggestion.
This commit is contained in:
@@ -10,14 +10,17 @@ class OnlyFred(models.Manager):
|
||||
def get_query_set(self):
|
||||
return super(OnlyFred, self).get_query_set().filter(name='fred')
|
||||
|
||||
|
||||
class OnlyBarney(models.Manager):
|
||||
def get_query_set(self):
|
||||
return super(OnlyBarney, self).get_query_set().filter(name='barney')
|
||||
|
||||
|
||||
class Value42(models.Manager):
|
||||
def get_query_set(self):
|
||||
return super(Value42, self).get_query_set().filter(value=42)
|
||||
|
||||
|
||||
class AbstractBase1(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
|
||||
@@ -29,6 +32,7 @@ class AbstractBase1(models.Model):
|
||||
manager2 = OnlyBarney()
|
||||
objects = models.Manager()
|
||||
|
||||
|
||||
class AbstractBase2(models.Model):
|
||||
value = models.IntegerField()
|
||||
|
||||
@@ -38,6 +42,7 @@ class AbstractBase2(models.Model):
|
||||
# Custom manager
|
||||
restricted = Value42()
|
||||
|
||||
|
||||
# No custom manager on this class to make sure the default case doesn't break.
|
||||
class AbstractBase3(models.Model):
|
||||
comment = models.CharField(max_length=50)
|
||||
@@ -45,6 +50,7 @@ class AbstractBase3(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Parent(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
@@ -54,6 +60,7 @@ class Parent(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
# Managers from base classes are inherited and, if no manager is specified
|
||||
# *and* the parent has a manager specified, the first one (in the MRO) will
|
||||
# become the default.
|
||||
@@ -64,6 +71,7 @@ class Child1(AbstractBase1):
|
||||
def __str__(self):
|
||||
return self.data
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Child2(AbstractBase1, AbstractBase2):
|
||||
data = models.CharField(max_length=25)
|
||||
@@ -71,6 +79,7 @@ class Child2(AbstractBase1, AbstractBase2):
|
||||
def __str__(self):
|
||||
return self.data
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Child3(AbstractBase1, AbstractBase3):
|
||||
data = models.CharField(max_length=25)
|
||||
@@ -78,6 +87,7 @@ class Child3(AbstractBase1, AbstractBase3):
|
||||
def __str__(self):
|
||||
return self.data
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Child4(AbstractBase1):
|
||||
data = models.CharField(max_length=25)
|
||||
@@ -89,6 +99,7 @@ class Child4(AbstractBase1):
|
||||
def __str__(self):
|
||||
return self.data
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Child5(AbstractBase3):
|
||||
name = models.CharField(max_length=25)
|
||||
@@ -99,10 +110,12 @@ class Child5(AbstractBase3):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
# Will inherit managers from AbstractBase1, but not Child4.
|
||||
class Child6(Child4):
|
||||
value = models.IntegerField()
|
||||
|
||||
|
||||
# Will not inherit default manager from parent.
|
||||
class Child7(Parent):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user