Fix PEP8 whitespace issues
autopep8 -r polymorphic/ example/ -i --select=E112,E113,E115,E116,E122,E123,E125,E127,E128,E201,E202,E203,E211,E225,E226,E227,E228,E231,E251,E261,E262,E271,E272,E273,E274,E301,E302,E303,E304,E309,E711,E713,W291,W293,W391 --exclude migrations,south_migrations (line conditiation fixes: E123,E125,E122,E127,E128)
This commit is contained in:
@@ -29,9 +29,9 @@ if django.VERSION[:2] < (1, 5):
|
||||
ct = self._get_from_cache(opts)
|
||||
except KeyError:
|
||||
ct, created = self.get_or_create(
|
||||
app_label = opts.app_label,
|
||||
model = opts.object_name.lower(),
|
||||
defaults = {'name': smart_text(opts.verbose_name_raw)},
|
||||
app_label=opts.app_label,
|
||||
model=opts.object_name.lower(),
|
||||
defaults={'name': smart_text(opts.verbose_name_raw)},
|
||||
)
|
||||
self._add_to_cache(self.db, ct)
|
||||
|
||||
@@ -39,4 +39,3 @@ if django.VERSION[:2] < (1, 5):
|
||||
|
||||
ContentTypeManager.get_for_model__original = ContentTypeManager.get_for_model
|
||||
ContentTypeManager.get_for_model = get_for_model
|
||||
|
||||
|
||||
+1
-26
@@ -42,6 +42,7 @@ class RegistrationClosed(RuntimeError):
|
||||
"The admin model can't be registered anymore at this point."
|
||||
pass
|
||||
|
||||
|
||||
class ChildAdminNotRegistered(RuntimeError):
|
||||
"The admin site for the model is not registered."
|
||||
pass
|
||||
@@ -122,13 +123,11 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
#: If your primary key consists of string values, update this regular expression.
|
||||
pk_regex = '(\d+|__fk__)'
|
||||
|
||||
|
||||
def __init__(self, model, admin_site, *args, **kwargs):
|
||||
super(PolymorphicParentModelAdmin, self).__init__(model, admin_site, *args, **kwargs)
|
||||
self._child_admin_site = self.admin_site.__class__(name=self.admin_site.name)
|
||||
self._is_setup = False
|
||||
|
||||
|
||||
def _lazy_setup(self):
|
||||
if self._is_setup:
|
||||
return
|
||||
@@ -150,7 +149,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
self._child_admin_site._registry = complete_registry
|
||||
self._is_setup = True
|
||||
|
||||
|
||||
def register_child(self, model, model_admin):
|
||||
"""
|
||||
Register a model with admin to display.
|
||||
@@ -167,7 +165,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
|
||||
self._child_admin_site.register(model, model_admin)
|
||||
|
||||
|
||||
def get_child_models(self):
|
||||
"""
|
||||
Return the derived model classes which this admin should handle.
|
||||
@@ -181,7 +178,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
|
||||
return self.child_models
|
||||
|
||||
|
||||
def get_child_type_choices(self, request, action):
|
||||
"""
|
||||
Return a list of polymorphic types for which the user has the permission to perform the given action.
|
||||
@@ -197,7 +193,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
choices.append((ct.id, model._meta.verbose_name))
|
||||
return choices
|
||||
|
||||
|
||||
def _get_real_admin(self, object_id):
|
||||
try:
|
||||
obj = self.model.objects.non_polymorphic() \
|
||||
@@ -206,7 +201,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
raise Http404
|
||||
return self._get_real_admin_by_ct(obj['polymorphic_ctype'])
|
||||
|
||||
|
||||
def _get_real_admin_by_ct(self, ct_id):
|
||||
try:
|
||||
ct = ContentType.objects.get_for_id(ct_id)
|
||||
@@ -219,7 +213,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
|
||||
return self._get_real_admin_by_model(model_class)
|
||||
|
||||
|
||||
def _get_real_admin_by_model(self, model_class):
|
||||
# In case of a ?ct_id=### parameter, the view is already checked for permissions.
|
||||
# Hence, make sure this is a derived object, or risk exposing other admin interfaces.
|
||||
@@ -233,7 +226,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
except KeyError:
|
||||
raise ChildAdminNotRegistered("No child admin site was registered for a '{0}' model.".format(model_class))
|
||||
|
||||
|
||||
def get_queryset(self, request):
|
||||
# optimize the list display.
|
||||
qs = super(PolymorphicParentModelAdmin, self).get_queryset(request)
|
||||
@@ -241,7 +233,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
qs = qs.non_polymorphic()
|
||||
return qs
|
||||
|
||||
|
||||
# For Django 1.5:
|
||||
def queryset(self, request):
|
||||
qs = super(PolymorphicParentModelAdmin, self).queryset(request)
|
||||
@@ -249,7 +240,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
qs = qs.non_polymorphic()
|
||||
return qs
|
||||
|
||||
|
||||
def add_view(self, request, form_url='', extra_context=None):
|
||||
"""Redirect the add view to the real admin."""
|
||||
ct_id = int(request.GET.get('ct_id', 0))
|
||||
@@ -266,13 +256,11 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
)
|
||||
return real_admin.add_view(request, form_url, extra_context)
|
||||
|
||||
|
||||
def change_view(self, request, object_id, *args, **kwargs):
|
||||
"""Redirect the change view to the real admin."""
|
||||
real_admin = self._get_real_admin(object_id)
|
||||
return real_admin.change_view(request, object_id, *args, **kwargs)
|
||||
|
||||
|
||||
def delete_view(self, request, object_id, extra_context=None):
|
||||
"""Redirect the delete view to the real admin."""
|
||||
real_admin = self._get_real_admin(object_id)
|
||||
@@ -331,7 +319,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
|
||||
return urls + custom_urls + dummy_urls
|
||||
|
||||
|
||||
def subclass_view(self, request, path):
|
||||
"""
|
||||
Forward any request to a custom view of the real admin.
|
||||
@@ -350,7 +337,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
|
||||
ct_id = self.model.objects.values_list('polymorphic_ctype_id', flat=True).get(pk=object_id)
|
||||
|
||||
|
||||
real_admin = self._get_real_admin_by_ct(ct_id)
|
||||
resolver = RegexURLResolver('^', real_admin.urls)
|
||||
resolvermatch = resolver.resolve(path) # May raise Resolver404
|
||||
@@ -359,7 +345,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
|
||||
return resolvermatch.func(request, *resolvermatch.args, **resolvermatch.kwargs)
|
||||
|
||||
|
||||
def add_type_view(self, request, form_url=''):
|
||||
"""
|
||||
Display a choice form to select which page type to add.
|
||||
@@ -402,7 +387,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
}
|
||||
return self.render_add_type_form(request, context, form_url)
|
||||
|
||||
|
||||
def render_add_type_form(self, request, context, form_url=''):
|
||||
"""
|
||||
Render the page type choice form.
|
||||
@@ -426,7 +410,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
"admin/add_type_form.html"
|
||||
], context, context_instance=context_instance)
|
||||
|
||||
|
||||
@property
|
||||
def change_list_template(self):
|
||||
opts = self.model._meta
|
||||
@@ -446,7 +429,6 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
|
||||
]
|
||||
|
||||
|
||||
|
||||
class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
The *optional* base class for the admin interface of derived models.
|
||||
@@ -465,7 +447,6 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||
base_fieldsets = None
|
||||
extra_fieldset_title = _("Contents") # Default title for extra fieldset
|
||||
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
# The django admin validation requires the form to have a 'class Meta: model = ..'
|
||||
# attribute, or it will complain that the fields are missing.
|
||||
@@ -482,7 +463,6 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||
|
||||
return super(PolymorphicChildModelAdmin, self).get_form(request, obj, **kwargs)
|
||||
|
||||
|
||||
@property
|
||||
def change_form_template(self):
|
||||
opts = self.model._meta
|
||||
@@ -502,7 +482,6 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||
"admin/change_form.html"
|
||||
]
|
||||
|
||||
|
||||
@property
|
||||
def delete_confirmation_template(self):
|
||||
opts = self.model._meta
|
||||
@@ -522,21 +501,18 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||
"admin/delete_confirmation.html"
|
||||
]
|
||||
|
||||
|
||||
def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
|
||||
context.update({
|
||||
'base_opts': self.base_model._meta,
|
||||
})
|
||||
return super(PolymorphicChildModelAdmin, self).render_change_form(request, context, add=add, change=change, form_url=form_url, obj=obj)
|
||||
|
||||
|
||||
def delete_view(self, request, object_id, context=None):
|
||||
extra_context = {
|
||||
'base_opts': self.base_model._meta,
|
||||
}
|
||||
return super(PolymorphicChildModelAdmin, self).delete_view(request, object_id, extra_context)
|
||||
|
||||
|
||||
# ---- Extra: improving the form/fieldset default display ----
|
||||
|
||||
def get_fieldsets(self, request, obj=None):
|
||||
@@ -557,7 +533,6 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
|
||||
else:
|
||||
return self.base_fieldsets
|
||||
|
||||
|
||||
def get_subclass_fields(self, request, obj=None):
|
||||
# Find out how many fields would really be on the form,
|
||||
# if it weren't restricted by declared fields.
|
||||
|
||||
+4
-4
@@ -57,7 +57,7 @@ class PolymorphicModelBase(ModelBase):
|
||||
|
||||
# Workaround compatibility issue with six.with_metaclass() and custom Django model metaclasses:
|
||||
if not attrs and model_name == 'NewBase':
|
||||
if django.VERSION < (1,5):
|
||||
if django.VERSION < (1, 5):
|
||||
# Let Django fully ignore the class which is inserted in between.
|
||||
# Django 1.5 fixed this, see https://code.djangoproject.com/ticket/19688
|
||||
attrs['__module__'] = 'django.utils.six'
|
||||
@@ -191,9 +191,9 @@ class PolymorphicModelBase(ModelBase):
|
||||
# app_label here for PolymorphicModel.
|
||||
meta = attrs.get('Meta', None)
|
||||
do_app_label_workaround = (meta
|
||||
and attrs['__module__'] == 'polymorphic'
|
||||
and model_name == 'PolymorphicModel'
|
||||
and getattr(meta, 'app_label', None) is None)
|
||||
and attrs['__module__'] == 'polymorphic'
|
||||
and model_name == 'PolymorphicModel'
|
||||
and getattr(meta, 'app_label', None) is None)
|
||||
|
||||
if do_app_label_workaround:
|
||||
meta.app_label = 'poly_dummy_app_label'
|
||||
|
||||
+15
-14
@@ -26,6 +26,7 @@ from .query_translate import translate_polymorphic_Q_object
|
||||
###################################################################################
|
||||
### PolymorphicModel
|
||||
|
||||
|
||||
class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||
"""
|
||||
Abstract base class that provides polymorphic behaviour
|
||||
@@ -56,7 +57,7 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||
|
||||
# avoid ContentType related field accessor clash (an error emitted by model validation)
|
||||
polymorphic_ctype = models.ForeignKey(ContentType, null=True, editable=False,
|
||||
related_name='polymorphic_%(app_label)s.%(class)s_set+')
|
||||
related_name='polymorphic_%(app_label)s.%(class)s_set+')
|
||||
|
||||
# some applications want to know the name of the fields that are added to its models
|
||||
polymorphic_internal_model_fields = ['polymorphic_ctype']
|
||||
@@ -110,8 +111,8 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||
# Protect against bad imports (dumpdata without --natural) or other
|
||||
# issues missing with the ContentType models.
|
||||
if model is not None \
|
||||
and not issubclass(model, self.__class__) \
|
||||
and not issubclass(model, self.__class__._meta.proxy_for_model):
|
||||
and not issubclass(model, self.__class__) \
|
||||
and not issubclass(model, self.__class__._meta.proxy_for_model):
|
||||
raise RuntimeError("ContentType {0} for {1} #{2} does not point to a subclass!".format(
|
||||
self.polymorphic_ctype_id, model, self.pk,
|
||||
))
|
||||
@@ -196,22 +197,22 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||
|
||||
def add_model_if_regular(model, field_name, result):
|
||||
if (issubclass(model, models.Model)
|
||||
and model != models.Model
|
||||
and model != self.__class__
|
||||
and model != PolymorphicModel):
|
||||
and model != models.Model
|
||||
and model != self.__class__
|
||||
and model != PolymorphicModel):
|
||||
add_model(model, field_name, result)
|
||||
|
||||
def add_all_super_models(model, result):
|
||||
def add_all_super_models(model, result):
|
||||
for super_cls, field_to_super in model._meta.parents.items():
|
||||
if field_to_super is not None: #if not a link to a proxy model
|
||||
field_name = field_to_super.name #the field on model can have a different name to super_cls._meta.module_name, if the field is created manually using 'parent_link'
|
||||
if field_to_super is not None: # if not a link to a proxy model
|
||||
field_name = field_to_super.name # the field on model can have a different name to super_cls._meta.module_name, if the field is created manually using 'parent_link'
|
||||
add_model_if_regular(super_cls, field_name, result)
|
||||
add_all_super_models(super_cls, result)
|
||||
|
||||
def add_all_sub_models(super_cls, result):
|
||||
for sub_cls in super_cls.__subclasses__(): #go through all subclasses of model
|
||||
if super_cls in sub_cls._meta.parents: #super_cls may not be in sub_cls._meta.parents if super_cls is a proxy model
|
||||
field_to_super = sub_cls._meta.parents[super_cls] #get the field that links sub_cls to super_cls
|
||||
def add_all_sub_models(super_cls, result):
|
||||
for sub_cls in super_cls.__subclasses__(): # go through all subclasses of model
|
||||
if super_cls in sub_cls._meta.parents: # super_cls may not be in sub_cls._meta.parents if super_cls is a proxy model
|
||||
field_to_super = sub_cls._meta.parents[super_cls] # get the field that links sub_cls to super_cls
|
||||
if field_to_super is not None: # if filed_to_super is not a link to a proxy model
|
||||
super_to_sub_related_field = field_to_super.rel
|
||||
if super_to_sub_related_field.related_name is None:
|
||||
@@ -220,7 +221,7 @@ class PolymorphicModel(six.with_metaclass(PolymorphicModelBase, models.Model)):
|
||||
else:
|
||||
#otherwise use the given related name
|
||||
to_subclass_fieldname = super_to_sub_related_field.related_name
|
||||
|
||||
|
||||
add_model_if_regular(sub_cls, to_subclass_fieldname, result)
|
||||
|
||||
result = {}
|
||||
|
||||
@@ -35,7 +35,7 @@ def transmogrify(cls, obj):
|
||||
else:
|
||||
# Run constructor, reassign values
|
||||
new = cls()
|
||||
for k,v in obj.__dict__.items():
|
||||
for k, v in obj.__dict__.items():
|
||||
new.__dict__[k] = v
|
||||
return new
|
||||
|
||||
@@ -72,7 +72,7 @@ class PolymorphicQuerySet(QuerySet):
|
||||
new.polymorphic_disabled = self.polymorphic_disabled
|
||||
return new
|
||||
|
||||
if django.VERSION >= (1,7):
|
||||
if django.VERSION >= (1, 7):
|
||||
def as_manager(cls):
|
||||
# Make sure the Django 1.7 way of creating managers works.
|
||||
from .manager import PolymorphicManager
|
||||
@@ -333,14 +333,15 @@ class PolymorphicQuerySet(QuerySet):
|
||||
def __repr__(self, *args, **kwargs):
|
||||
if self.model.polymorphic_query_multiline_output:
|
||||
result = [repr(o) for o in self.all()]
|
||||
return '[ ' + ',\n '.join(result) + ' ]'
|
||||
return '[ ' + ',\n '.join(result) + ' ]'
|
||||
else:
|
||||
return super(PolymorphicQuerySet, self).__repr__(*args, **kwargs)
|
||||
|
||||
class _p_list_class(list):
|
||||
|
||||
def __repr__(self, *args, **kwargs):
|
||||
result = [repr(o) for o in self]
|
||||
return '[ ' + ',\n '.join(result) + ' ]'
|
||||
return '[ ' + ',\n '.join(result) + ' ]'
|
||||
|
||||
def get_real_instances(self, base_result_objects=None):
|
||||
"same as _get_real_instances, but make sure that __repr__ for ShowField... creates correct output"
|
||||
|
||||
@@ -248,7 +248,7 @@ def _create_model_filter_Q(modellist, not_instance_of=False):
|
||||
q = q | q_class_with_subclasses(subclass)
|
||||
return q
|
||||
|
||||
qlist = [q_class_with_subclasses(m) for m in modellist]
|
||||
qlist = [q_class_with_subclasses(m) for m in modellist]
|
||||
|
||||
q_ored = reduce(lambda a, b: a | b, qlist)
|
||||
if not_instance_of:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
|
||||
|
||||
class ShowFieldBase(object):
|
||||
""" base class for the ShowField... model mixins, does the work """
|
||||
|
||||
@@ -119,8 +120,8 @@ class ShowFieldBase(object):
|
||||
next_new_section, _, _ = parts[i + 1]
|
||||
|
||||
if (self.polymorphic_showfield_max_line_width
|
||||
and xpos + len(p) > self.polymorphic_showfield_max_line_width
|
||||
and possible_line_break_pos != None):
|
||||
and xpos + len(p) > self.polymorphic_showfield_max_line_width
|
||||
and possible_line_break_pos != None):
|
||||
rest = out[possible_line_break_pos:]
|
||||
out = out[:possible_line_break_pos]
|
||||
out += '\n' + indentstr + rest
|
||||
|
||||
@@ -5,6 +5,7 @@ register = Library()
|
||||
|
||||
|
||||
class BreadcrumbScope(Node):
|
||||
|
||||
def __init__(self, base_opts, nodelist):
|
||||
self.base_opts = base_opts
|
||||
self.nodelist = nodelist # Note, takes advantage of Node.child_nodelists
|
||||
@@ -25,7 +26,6 @@ class BreadcrumbScope(Node):
|
||||
else:
|
||||
raise TemplateSyntaxError("{0} tag expects 1 argument".format(token.contents[0]))
|
||||
|
||||
|
||||
def render(self, context):
|
||||
# app_label is really hard to overwrite in the standard Django ModelAdmin.
|
||||
# To insert it in the template, the entire render_change_form() and delete_view() have to copied and adjusted.
|
||||
|
||||
+139
-44
@@ -14,7 +14,7 @@ except ImportError:
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
from django.test import TestCase
|
||||
from django.db.models import Q,Count
|
||||
from django.db.models import Q, Count
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.utils import six
|
||||
@@ -32,85 +32,133 @@ except ImportError:
|
||||
|
||||
class PlainA(models.Model):
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class PlainB(PlainA):
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class PlainC(PlainB):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class Model2A(ShowFieldType, PolymorphicModel):
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class Model2B(Model2A):
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class Model2C(Model2B):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class Model2D(Model2C):
|
||||
field4 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ModelExtraA(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ModelExtraB(ModelExtraA):
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ModelExtraC(ModelExtraB):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ModelExtraExternal(models.Model):
|
||||
topic = models.CharField(max_length=10)
|
||||
|
||||
class ModelShow1(ShowFieldType,PolymorphicModel):
|
||||
|
||||
class ModelShow1(ShowFieldType, PolymorphicModel):
|
||||
field1 = models.CharField(max_length=10)
|
||||
m2m = models.ManyToManyField('self')
|
||||
|
||||
|
||||
class ModelShow2(ShowFieldContent, PolymorphicModel):
|
||||
field1 = models.CharField(max_length=10)
|
||||
m2m = models.ManyToManyField('self')
|
||||
|
||||
|
||||
class ModelShow3(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
field1 = models.CharField(max_length=10)
|
||||
m2m = models.ManyToManyField('self')
|
||||
|
||||
|
||||
class ModelShow1_plain(PolymorphicModel):
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ModelShow2_plain(ModelShow1_plain):
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class Base(ShowFieldType, PolymorphicModel):
|
||||
field_b = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ModelX(Base):
|
||||
field_x = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ModelY(Base):
|
||||
field_y = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class Enhance_Plain(models.Model):
|
||||
field_p = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class Enhance_Base(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
base_id = models.AutoField(primary_key=True)
|
||||
field_b = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class Enhance_Inherit(Enhance_Base, Enhance_Plain):
|
||||
field_i = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class RelationBase(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
field_base = models.CharField(max_length=10)
|
||||
fk = models.ForeignKey('self', null=True, related_name='relationbase_set')
|
||||
m2m = models.ManyToManyField('self')
|
||||
|
||||
|
||||
class RelationA(RelationBase):
|
||||
field_a = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class RelationB(RelationBase):
|
||||
field_b = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class RelationBC(RelationB):
|
||||
field_c = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class RelatingModel(models.Model):
|
||||
many2many = models.ManyToManyField(Model2A)
|
||||
|
||||
|
||||
class One2OneRelatingModel(PolymorphicModel):
|
||||
one2one = models.OneToOneField(Model2A)
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class One2OneRelatingModelDerived(One2OneRelatingModel):
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class MyManagerQuerySet(PolymorphicQuerySet):
|
||||
|
||||
def my_queryset_foo(self):
|
||||
return self.all() # Just a method to prove the existance of the custom queryset.
|
||||
|
||||
|
||||
class MyManager(PolymorphicManager):
|
||||
queryset_class = MyManagerQuerySet
|
||||
|
||||
@@ -120,27 +168,38 @@ class MyManager(PolymorphicManager):
|
||||
# Django <= 1.5 compatibility
|
||||
get_query_set = get_queryset
|
||||
|
||||
|
||||
class ModelWithMyManager(ShowFieldTypeAndContent, Model2A):
|
||||
objects = MyManager()
|
||||
field4 = models.CharField(max_length=10)
|
||||
|
||||
if django.VERSION >= (1,7):
|
||||
if django.VERSION >= (1, 7):
|
||||
class ModelWithMyManager2(ShowFieldTypeAndContent, Model2A):
|
||||
objects = MyManagerQuerySet.as_manager()
|
||||
field4 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class MROBase1(ShowFieldType, PolymorphicModel):
|
||||
objects = MyManager()
|
||||
field1 = models.CharField(max_length=10) # needed as MyManager uses it
|
||||
field1 = models.CharField(max_length=10) # needed as MyManager uses it
|
||||
|
||||
|
||||
class MROBase2(MROBase1):
|
||||
pass # Django vanilla inheritance does not inherit MyManager as _default_manager here
|
||||
pass # Django vanilla inheritance does not inherit MyManager as _default_manager here
|
||||
|
||||
|
||||
class MROBase3(models.Model):
|
||||
objects = PolymorphicManager()
|
||||
|
||||
|
||||
class MRODerived(MROBase2, MROBase3):
|
||||
pass
|
||||
|
||||
|
||||
class ParentModelWithManager(PolymorphicModel):
|
||||
pass
|
||||
|
||||
|
||||
class ChildModelWithManager(PolymorphicModel):
|
||||
# Also test whether foreign keys receive the manager:
|
||||
fk = models.ForeignKey(ParentModelWithManager, related_name='childmodel_set')
|
||||
@@ -148,10 +207,13 @@ class ChildModelWithManager(PolymorphicModel):
|
||||
|
||||
|
||||
class PlainMyManagerQuerySet(QuerySet):
|
||||
|
||||
def my_queryset_foo(self):
|
||||
return self.all() # Just a method to prove the existance of the custom queryset.
|
||||
|
||||
|
||||
class PlainMyManager(models.Manager):
|
||||
|
||||
def my_queryset_foo(self):
|
||||
return self.get_queryset().my_queryset_foo()
|
||||
|
||||
@@ -161,9 +223,11 @@ class PlainMyManager(models.Manager):
|
||||
# Django <= 1.5 compatibility
|
||||
get_query_set = get_queryset
|
||||
|
||||
|
||||
class PlainParentModelWithManager(models.Model):
|
||||
pass
|
||||
|
||||
|
||||
class PlainChildModelWithManager(models.Model):
|
||||
fk = models.ForeignKey(PlainParentModelWithManager, related_name='childmodel_set')
|
||||
objects = PlainMyManager()
|
||||
@@ -173,82 +237,132 @@ class MgrInheritA(models.Model):
|
||||
mgrA = models.Manager()
|
||||
mgrA2 = models.Manager()
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class MgrInheritB(MgrInheritA):
|
||||
mgrB = models.Manager()
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class MgrInheritC(ShowFieldTypeAndContent, MgrInheritB):
|
||||
pass
|
||||
|
||||
|
||||
class BlogBase(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
name = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class BlogA(BlogBase):
|
||||
info = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class BlogB(BlogBase):
|
||||
pass
|
||||
|
||||
|
||||
class BlogEntry(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
blog = models.ForeignKey(BlogA)
|
||||
text = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class BlogEntry_limit_choices_to(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
blog = models.ForeignKey(BlogBase)
|
||||
text = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ModelFieldNameTest(ShowFieldType, PolymorphicModel):
|
||||
modelfieldnametest = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class InitTestModel(ShowFieldType, PolymorphicModel):
|
||||
bar = models.CharField(max_length=100)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['bar'] = self.x()
|
||||
super(InitTestModel, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class InitTestModelSubclass(InitTestModel):
|
||||
|
||||
def x(self):
|
||||
return 'XYZ'
|
||||
|
||||
# models from github issue
|
||||
|
||||
|
||||
class Top(PolymorphicModel):
|
||||
name = models.CharField(max_length=50)
|
||||
|
||||
class Meta:
|
||||
ordering = ('pk',)
|
||||
|
||||
|
||||
class Middle(Top):
|
||||
description = models.TextField()
|
||||
|
||||
|
||||
class Bottom(Middle):
|
||||
author = models.CharField(max_length=50)
|
||||
|
||||
|
||||
class UUIDProject(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
uuid_primary_key = UUIDField(primary_key = True, default=uuid.uuid1)
|
||||
topic = models.CharField(max_length = 30)
|
||||
uuid_primary_key = UUIDField(primary_key=True, default=uuid.uuid1)
|
||||
topic = models.CharField(max_length=30)
|
||||
|
||||
|
||||
class UUIDArtProject(UUIDProject):
|
||||
artist = models.CharField(max_length = 30)
|
||||
artist = models.CharField(max_length=30)
|
||||
|
||||
|
||||
class UUIDResearchProject(UUIDProject):
|
||||
supervisor = models.CharField(max_length = 30)
|
||||
supervisor = models.CharField(max_length=30)
|
||||
|
||||
|
||||
class UUIDPlainA(models.Model):
|
||||
uuid_primary_key = UUIDField(primary_key = True, default=uuid.uuid1)
|
||||
uuid_primary_key = UUIDField(primary_key=True, default=uuid.uuid1)
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class UUIDPlainB(UUIDPlainA):
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class UUIDPlainC(UUIDPlainB):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
||||
# base -> proxy
|
||||
|
||||
|
||||
class ProxyBase(PolymorphicModel):
|
||||
some_data = models.CharField(max_length=128)
|
||||
|
||||
|
||||
class ProxyChild(ProxyBase):
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
|
||||
class NonProxyChild(ProxyBase):
|
||||
name=models.CharField(max_length=10)
|
||||
name = models.CharField(max_length=10)
|
||||
|
||||
# base -> proxy -> real models
|
||||
|
||||
|
||||
class ProxiedBase(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
name = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ProxyModelBase(ProxiedBase):
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
|
||||
class ProxyModelA(ProxyModelBase):
|
||||
field1 = models.CharField(max_length=10)
|
||||
|
||||
|
||||
class ProxyModelB(ProxyModelBase):
|
||||
field2 = models.CharField(max_length=10)
|
||||
|
||||
@@ -264,11 +378,16 @@ class RelatedNameClash(ShowFieldType, PolymorphicModel):
|
||||
ctype = models.ForeignKey(ContentType, null=True, editable=False)
|
||||
|
||||
#class with a parent_link to superclass, and a related_name back to subclass
|
||||
|
||||
|
||||
class TestParentLinkAndRelatedName(ModelShow1_plain):
|
||||
superclass = models.OneToOneField(ModelShow1_plain, parent_link=True, related_name='related_name_subclass')
|
||||
|
||||
|
||||
class CustomPkBase(ShowFieldTypeAndContent, PolymorphicModel):
|
||||
b = models.CharField(max_length=1)
|
||||
|
||||
|
||||
class CustomPkInherit(CustomPkBase):
|
||||
custom_id = models.AutoField(primary_key=True)
|
||||
i = models.CharField(max_length=1)
|
||||
@@ -323,7 +442,7 @@ class PolymorphicTests(TestCase):
|
||||
|
||||
# test ordering for field in one subclass only
|
||||
# MySQL and SQLite return this order
|
||||
expected1='''
|
||||
expected1 = '''
|
||||
[ <BlogA: id 8, name (CharField) "B5", info (CharField) "i5">,
|
||||
<BlogA: id 7, name (CharField) "B4", info (CharField) "i4">,
|
||||
<BlogA: id 6, name (CharField) "B3", info (CharField) "i3">,
|
||||
@@ -334,7 +453,7 @@ class PolymorphicTests(TestCase):
|
||||
<BlogB: id 4, name (CharField) "Bb3"> ]'''
|
||||
|
||||
# PostgreSQL returns this order
|
||||
expected2='''
|
||||
expected2 = '''
|
||||
[ <BlogB: id 2, name (CharField) "Bb1">,
|
||||
<BlogB: id 3, name (CharField) "Bb2">,
|
||||
<BlogB: id 4, name (CharField) "Bb3">,
|
||||
@@ -347,7 +466,6 @@ class PolymorphicTests(TestCase):
|
||||
x = '\n' + repr(BlogBase.objects.order_by('-BlogA___info'))
|
||||
self.assertTrue(x == expected1 or x == expected2)
|
||||
|
||||
|
||||
def test_limit_choices_to(self):
|
||||
"""
|
||||
this is not really a testcase, as limit_choices_to only affects the Django admin
|
||||
@@ -359,7 +477,6 @@ class PolymorphicTests(TestCase):
|
||||
entry1 = BlogEntry_limit_choices_to.objects.create(blog=blog_b, text='bla2')
|
||||
entry2 = BlogEntry_limit_choices_to.objects.create(blog=blog_b, text='bla2')
|
||||
|
||||
|
||||
def test_primary_key_custom_field_problem(self):
|
||||
"""
|
||||
object retrieval problem occuring with some custom primary key fields (UUIDField as test case)
|
||||
@@ -377,7 +494,7 @@ class PolymorphicTests(TestCase):
|
||||
self.assertIsInstance(a.uuid_primary_key, uuid.UUID)
|
||||
self.assertIsInstance(a.pk, uuid.UUID)
|
||||
|
||||
res = re.sub(' "(.*?)..", topic',', topic', repr(qs))
|
||||
res = re.sub(' "(.*?)..", topic', ', topic', repr(qs))
|
||||
res_exp = """[ <UUIDProject: uuid_primary_key (UUIDField/pk), topic (CharField) "John's gathering">,
|
||||
<UUIDArtProject: uuid_primary_key (UUIDField/pk), topic (CharField) "Sculpting with Tim", artist (CharField) "T. Turner">,
|
||||
<UUIDResearchProject: uuid_primary_key (UUIDField/pk), topic (CharField) "Swallow Aerodynamics", supervisor (CharField) "Dr. Winter"> ]"""
|
||||
@@ -401,7 +518,6 @@ class PolymorphicTests(TestCase):
|
||||
Model2C.objects.create(field1='C1', field2='C2', field3='C3')
|
||||
Model2D.objects.create(field1='D1', field2='D2', field3='D3', field4='D4')
|
||||
|
||||
|
||||
def test_simple_inheritance(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
@@ -411,14 +527,12 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[2]), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||
self.assertEqual(repr(objects[3]), '<Model2D: id 4, field1 (CharField), field2 (CharField), field3 (CharField), field4 (CharField)>')
|
||||
|
||||
|
||||
def test_manual_get_real_instance(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
o = Model2A.objects.non_polymorphic().get(field1='C1')
|
||||
self.assertEqual(repr(o.get_real_instance()), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||
|
||||
|
||||
def test_non_polymorphic(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
@@ -428,7 +542,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[2]), '<Model2A: id 3, field1 (CharField)>')
|
||||
self.assertEqual(repr(objects[3]), '<Model2A: id 4, field1 (CharField)>')
|
||||
|
||||
|
||||
def test_get_real_instances(self):
|
||||
self.create_model2abcd()
|
||||
qs = Model2A.objects.all().non_polymorphic()
|
||||
@@ -447,7 +560,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[2]), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||
self.assertEqual(repr(objects[3]), '<Model2D: id 4, field1 (CharField), field2 (CharField), field3 (CharField), field4 (CharField)>')
|
||||
|
||||
|
||||
def test_translate_polymorphic_q_object(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
@@ -456,7 +568,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[0]), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||
self.assertEqual(repr(objects[1]), '<Model2D: id 4, field1 (CharField), field2 (CharField), field3 (CharField), field4 (CharField)>')
|
||||
|
||||
|
||||
def test_base_manager(self):
|
||||
def show_base_manager(model):
|
||||
return "{0} {1}".format(
|
||||
@@ -475,7 +586,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(show_base_manager(One2OneRelatingModel), "<class 'polymorphic.manager.PolymorphicManager'> <class 'polymorphic.tests.One2OneRelatingModel'>")
|
||||
self.assertEqual(show_base_manager(One2OneRelatingModelDerived), "<class 'django.db.models.manager.Manager'> <class 'polymorphic.tests.One2OneRelatingModelDerived'>")
|
||||
|
||||
|
||||
def test_instance_default_manager(self):
|
||||
def show_default_manager(instance):
|
||||
return "{0} {1}".format(
|
||||
@@ -508,7 +618,6 @@ class PolymorphicTests(TestCase):
|
||||
object2b = Model2B.base_objects.get(field1='C1')
|
||||
self.assertEqual(repr(object2b.model2c), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||
|
||||
|
||||
def test_onetoone_field(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
@@ -522,7 +631,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(c.one2one), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||
self.assertEqual(repr(a.one2onerelatingmodel), '<One2OneRelatingModelDerived: One2OneRelatingModelDerived object>')
|
||||
|
||||
|
||||
def test_manytomany_field(self):
|
||||
# Model 1
|
||||
o = ModelShow1.objects.create(field1='abc')
|
||||
@@ -537,7 +645,7 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(ModelShow2.objects.all()), '[ <ModelShow2: id 1, field1 "abc", m2m 1> ]')
|
||||
|
||||
# Model 3
|
||||
o=ModelShow3.objects.create(field1='abc')
|
||||
o = ModelShow3.objects.create(field1='abc')
|
||||
o.m2m.add(o)
|
||||
o.save()
|
||||
self.assertEqual(repr(ModelShow3.objects.all()), '[ <ModelShow3: id 1, field1 (CharField) "abc", m2m (ManyToManyField) 1> ]')
|
||||
@@ -550,7 +658,6 @@ class PolymorphicTests(TestCase):
|
||||
ModelShow2_plain.objects.create(field1='abc', field2='def')
|
||||
self.assertEqual(repr(ModelShow1_plain.objects.all()), '[<ModelShow1_plain: ModelShow1_plain object>, <ModelShow2_plain: ModelShow2_plain object>]')
|
||||
|
||||
|
||||
def test_extra_method(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
@@ -569,7 +676,7 @@ class PolymorphicTests(TestCase):
|
||||
ModelExtraExternal.objects.create(topic='extra1')
|
||||
ModelExtraExternal.objects.create(topic='extra2')
|
||||
ModelExtraExternal.objects.create(topic='extra3')
|
||||
objects = ModelExtraA.objects.extra(tables=["polymorphic_modelextraexternal"], select={"topic":"polymorphic_modelextraexternal.topic"}, where=["polymorphic_modelextraa.id = polymorphic_modelextraexternal.id"])
|
||||
objects = ModelExtraA.objects.extra(tables=["polymorphic_modelextraexternal"], select={"topic": "polymorphic_modelextraexternal.topic"}, where=["polymorphic_modelextraa.id = polymorphic_modelextraexternal.id"])
|
||||
if six.PY3:
|
||||
self.assertEqual(repr(objects[0]), '<ModelExtraA: id 1, field1 (CharField) "A1" - Extra: topic (str) "extra1">')
|
||||
self.assertEqual(repr(objects[1]), '<ModelExtraB: id 2, field1 (CharField) "B1", field2 (CharField) "B2" - Extra: topic (str) "extra2">')
|
||||
@@ -580,7 +687,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[2]), '<ModelExtraC: id 3, field1 (CharField) "C1", field2 (CharField) "C2", field3 (CharField) "C3" - Extra: topic (unicode) "extra3">')
|
||||
self.assertEqual(len(objects), 3)
|
||||
|
||||
|
||||
def test_instance_of_filter(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
@@ -606,16 +712,14 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[0]), '<Model2A: id 1, field1 (CharField)>')
|
||||
self.assertEqual(len(objects), 1)
|
||||
|
||||
|
||||
def test_polymorphic___filter(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
objects = Model2A.objects.filter(Q( Model2B___field2='B2') | Q( Model2C___field3='C3'))
|
||||
objects = Model2A.objects.filter(Q(Model2B___field2='B2') | Q(Model2C___field3='C3'))
|
||||
self.assertEqual(len(objects), 2)
|
||||
self.assertEqual(repr(objects[0]), '<Model2B: id 2, field1 (CharField), field2 (CharField)>')
|
||||
self.assertEqual(repr(objects[1]), '<Model2C: id 3, field1 (CharField), field2 (CharField), field3 (CharField)>')
|
||||
|
||||
|
||||
def test_delete(self):
|
||||
self.create_model2abcd()
|
||||
|
||||
@@ -630,7 +734,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[2]), '<Model2D: id 4, field1 (CharField), field2 (CharField), field3 (CharField), field4 (CharField)>')
|
||||
self.assertEqual(len(objects), 3)
|
||||
|
||||
|
||||
def test_combine_querysets(self):
|
||||
ModelX.objects.create(field_x='x')
|
||||
ModelY.objects.create(field_y='y')
|
||||
@@ -640,7 +743,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(qs[1]), '<ModelY: id 2, field_b (CharField), field_y (CharField)>')
|
||||
self.assertEqual(len(qs), 2)
|
||||
|
||||
|
||||
def test_multiple_inheritance(self):
|
||||
# multiple inheritance, subclassing third party models (mix PolymorphicModel with models.Model)
|
||||
|
||||
@@ -685,7 +787,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(repr(objects[1]), '<RelationB: id 3, field_base (CharField) "B1", fk (ForeignKey) RelationA, field_b (CharField) "B2", m2m (ManyToManyField) 1>')
|
||||
self.assertEqual(len(objects), 2)
|
||||
|
||||
|
||||
def test_user_defined_manager(self):
|
||||
self.create_model2abcd()
|
||||
ModelWithMyManager.objects.create(field1='D1a', field4='D4a')
|
||||
@@ -700,7 +801,7 @@ class PolymorphicTests(TestCase):
|
||||
self.assertIs(type(ModelWithMyManager._default_manager), MyManager)
|
||||
self.assertIs(type(ModelWithMyManager.base_objects), models.Manager)
|
||||
|
||||
@skipIf(django.VERSION < (1,7), "This test needs Django 1.7+")
|
||||
@skipIf(django.VERSION < (1, 7), "This test needs Django 1.7+")
|
||||
def test_user_defined_queryset_as_manager(self):
|
||||
self.create_model2abcd()
|
||||
ModelWithMyManager2.objects.create(field1='D1a', field4='D4a')
|
||||
@@ -715,7 +816,6 @@ class PolymorphicTests(TestCase):
|
||||
self.assertEqual(type(ModelWithMyManager2._default_manager).__name__, 'PolymorphicManagerFromMyManagerQuerySet')
|
||||
self.assertIs(type(ModelWithMyManager2.base_objects), models.Manager)
|
||||
|
||||
|
||||
def test_manager_inheritance(self):
|
||||
# by choice of MRO, should be MyManager from MROBase1.
|
||||
self.assertIs(type(MRODerived.objects), MyManager)
|
||||
@@ -726,7 +826,6 @@ class PolymorphicTests(TestCase):
|
||||
# Django vanilla inheritance does not inherit MyManager as _default_manager here
|
||||
self.assertIs(type(MROBase2._default_manager), MyManager)
|
||||
|
||||
|
||||
def test_queryset_assignment(self):
|
||||
# This is just a consistency check for now, testing standard Django behavior.
|
||||
parent = PlainParentModelWithManager.objects.create()
|
||||
@@ -750,7 +849,6 @@ class PolymorphicTests(TestCase):
|
||||
# A related set is created using the model's _default_manager, so does gain extra methods.
|
||||
self.assertIs(type(parent.childmodel_set.my_queryset_foo()), MyManagerQuerySet)
|
||||
|
||||
|
||||
def test_proxy_models(self):
|
||||
# prepare some data
|
||||
for data in ('bleep bloop', 'I am a', 'computer'):
|
||||
@@ -771,7 +869,7 @@ class PolymorphicTests(TestCase):
|
||||
This unit test guards that this check is working properly. For instance,
|
||||
proxy child models need to be handled separately.
|
||||
"""
|
||||
name="Item1"
|
||||
name = "Item1"
|
||||
nonproxychild = NonProxyChild.objects.create(name=name)
|
||||
|
||||
pb = ProxyBase.objects.get(id=1)
|
||||
@@ -792,7 +890,6 @@ class PolymorphicTests(TestCase):
|
||||
ct = ContentType.objects.get_for_model(ProxyChild, for_concrete_model=False)
|
||||
self.assertEqual(ProxyChild, ct.model_class())
|
||||
|
||||
|
||||
def test_proxy_model_inheritance(self):
|
||||
"""
|
||||
Polymorphic abilities should also work when the base model is a proxy object.
|
||||
@@ -852,7 +949,7 @@ class PolymorphicTests(TestCase):
|
||||
|
||||
#check that the accessors to parent and sublass work correctly and return the right object
|
||||
p = ModelShow1_plain.objects.non_polymorphic().get(field1="TestParentLinkAndRelatedName")
|
||||
self.assertNotEqual(p, t) #p should be Plain1 and t TestParentLinkAndRelatedName, so not equal
|
||||
self.assertNotEqual(p, t) # p should be Plain1 and t TestParentLinkAndRelatedName, so not equal
|
||||
self.assertEqual(p, t.superclass)
|
||||
self.assertEqual(p.related_name_subclass, t)
|
||||
|
||||
@@ -860,7 +957,6 @@ class PolymorphicTests(TestCase):
|
||||
t.delete()
|
||||
|
||||
|
||||
|
||||
class RegressionTests(TestCase):
|
||||
|
||||
def test_for_query_result_incomplete_with_inheritance(self):
|
||||
@@ -881,4 +977,3 @@ class RegressionTests(TestCase):
|
||||
|
||||
expected_queryset = [bottom]
|
||||
self.assertQuerysetEqual(Bottom.objects.all(), [repr(r) for r in expected_queryset])
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class UUIDField(six.with_metaclass(models.SubfieldBase, models.CharField)):
|
||||
self.namespace, self.name = namespace, name
|
||||
|
||||
super(UUIDField, self).__init__(verbose_name=verbose_name,
|
||||
name=name, **kwargs)
|
||||
name=name, **kwargs)
|
||||
|
||||
def create_uuid(self):
|
||||
if not self.version or self.version == 4:
|
||||
@@ -139,6 +139,6 @@ class UUIDField(six.with_metaclass(models.SubfieldBase, models.CharField)):
|
||||
defaults = {
|
||||
'form_class': forms.CharField,
|
||||
'max_length': self.max_length
|
||||
}
|
||||
}
|
||||
defaults.update(kwargs)
|
||||
return super(UUIDField, self).formfield(**defaults)
|
||||
|
||||
Reference in New Issue
Block a user