Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #21940 -- Added kwargs to contribute_to_class() of model fields..

Thanks Kronuz for the suggestion.
  • Loading branch information...
commit 1ed6fbcf44f0eebf29fd9b36be03bc5d73acee0a 1 parent a0bfe4e
@mitar mitar authored timgraham committed
View
7 django/contrib/contenttypes/fields.py
@@ -28,7 +28,7 @@ def __init__(self, ct_field="content_type", fk_field="object_id", for_concrete_m
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 @@ def value_to_string(self, obj):
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
View
4 django/contrib/gis/db/models/fields.py
@@ -210,8 +210,8 @@ def get_srid(self, geom):
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))
View
8 django/db/models/fields/__init__.py
@@ -914,10 +914,10 @@ def get_prep_value(self, value):
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 @@ def pre_save(self, model_instance, add):
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,
View
8 django/db/models/fields/files.py
@@ -300,8 +300,8 @@ def pre_save(self, model_instance, add):
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 @@ def deconstruct(self):
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.
View
4 django/db/models/fields/related.py
@@ -2263,7 +2263,7 @@ def value_to_string(self, obj):
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 @@ def contribute_to_class(self, cls, name):
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
View
6 django/db/models/fields/subclassing.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.