mirror of https://github.com/django/django.git
Fixed #21940 -- Added kwargs to contribute_to_class() of model fields..
Thanks Kronuz for the suggestion.
This commit is contained in:
parent
a0bfe4ea98
commit
1ed6fbcf44
|
@ -28,7 +28,7 @@ class GenericForeignKey(object):
|
|||
self.for_concrete_model = for_concrete_model
|
||||
self.editable = False
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
self.name = name
|
||||
self.model = cls
|
||||
self.cache_attr = "_%s_cache" % name
|
||||
|
@ -316,8 +316,9 @@ class GenericRelation(ForeignObject):
|
|||
qs = getattr(obj, self.name).all()
|
||||
return smart_text([instance._get_pk_val() for instance in qs])
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
super(GenericRelation, self).contribute_to_class(cls, name, virtual_only=True)
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
kwargs['virtual_only'] = True
|
||||
super(GenericRelation, self).contribute_to_class(cls, name, **kwargs)
|
||||
# Save a reference to which model this class is on for future use
|
||||
self.model = cls
|
||||
# Add the descriptor for the relation
|
||||
|
|
|
@ -210,8 +210,8 @@ class GeometryField(Field):
|
|||
return gsrid
|
||||
|
||||
### Routines overloaded from Field ###
|
||||
def contribute_to_class(self, cls, name):
|
||||
super(GeometryField, self).contribute_to_class(cls, name)
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
super(GeometryField, self).contribute_to_class(cls, name, **kwargs)
|
||||
|
||||
# Setup for lazy-instantiated Geometry object.
|
||||
setattr(cls, self.attname, GeometryProxy(Geometry, self))
|
||||
|
|
|
@ -914,10 +914,10 @@ class AutoField(Field):
|
|||
return None
|
||||
return int(value)
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
assert not cls._meta.has_auto_field, \
|
||||
"A model can't have more than one AutoField."
|
||||
super(AutoField, self).contribute_to_class(cls, name)
|
||||
super(AutoField, self).contribute_to_class(cls, name, **kwargs)
|
||||
cls._meta.has_auto_field = True
|
||||
cls._meta.auto_field = self
|
||||
|
||||
|
@ -1226,8 +1226,8 @@ class DateField(DateTimeCheckMixin, Field):
|
|||
else:
|
||||
return super(DateField, self).pre_save(model_instance, add)
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
super(DateField, self).contribute_to_class(cls, name)
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
super(DateField, self).contribute_to_class(cls, name, **kwargs)
|
||||
if not self.null:
|
||||
setattr(cls, 'get_next_by_%s' % self.name,
|
||||
curry(cls._get_next_or_previous_by_FIELD, field=self,
|
||||
|
|
|
@ -300,8 +300,8 @@ class FileField(Field):
|
|||
file.save(file.name, file, save=False)
|
||||
return file
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
super(FileField, self).contribute_to_class(cls, name)
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
super(FileField, self).contribute_to_class(cls, name, **kwargs)
|
||||
setattr(cls, self.name, self.descriptor_class(self))
|
||||
|
||||
def get_directory_name(self):
|
||||
|
@ -407,8 +407,8 @@ class ImageField(FileField):
|
|||
kwargs['height_field'] = self.height_field
|
||||
return name, path, args, kwargs
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
super(ImageField, self).contribute_to_class(cls, name)
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
super(ImageField, self).contribute_to_class(cls, name, **kwargs)
|
||||
# Attach update_dimension_fields so that dimension fields declared
|
||||
# after their corresponding image field don't stay cleared by
|
||||
# Model.__init__, see bug #11196.
|
||||
|
|
|
@ -2263,7 +2263,7 @@ class ManyToManyField(RelatedField):
|
|||
data = [choices_list[0][0]]
|
||||
return smart_text(data)
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
# To support multiple relations to self, it's useful to have a non-None
|
||||
# related name on symmetrical relations for internal reasons. The
|
||||
# concept doesn't make a lot of sense externally ("you want me to
|
||||
|
@ -2273,7 +2273,7 @@ class ManyToManyField(RelatedField):
|
|||
if self.rel.symmetrical and (self.rel.to == "self" or self.rel.to == cls._meta.object_name):
|
||||
self.rel.related_name = "%s_rel_+" % name
|
||||
|
||||
super(ManyToManyField, self).contribute_to_class(cls, name)
|
||||
super(ManyToManyField, self).contribute_to_class(cls, name, **kwargs)
|
||||
|
||||
# The intermediate m2m model is not auto created if:
|
||||
# 1) There is a manually specified intermediate, or
|
||||
|
|
|
@ -46,11 +46,11 @@ def make_contrib(superclass, func=None):
|
|||
case that the existing contribute_to_class() calls all the necessary
|
||||
superclass methods.
|
||||
"""
|
||||
def contribute_to_class(self, cls, name):
|
||||
def contribute_to_class(self, cls, name, **kwargs):
|
||||
if func:
|
||||
func(self, cls, name)
|
||||
func(self, cls, name, **kwargs)
|
||||
else:
|
||||
super(superclass, self).contribute_to_class(cls, name)
|
||||
super(superclass, self).contribute_to_class(cls, name, **kwargs)
|
||||
setattr(cls, self.name, Creator(self))
|
||||
|
||||
return contribute_to_class
|
||||
|
|
Loading…
Reference in New Issue