summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitar <mitar.git@tnode.com>2014-07-23 11:41:06 +0200
committerTim Graham <timograham@gmail.com>2014-08-01 07:41:28 -0400
commit1ed6fbcf44f0eebf29fd9b36be03bc5d73acee0a (patch)
tree78cd0dc1cb0a291d04d3c32c3d033077f5cf864a
parenta0bfe4ea984fbf1720c24de42310c48b72f75f08 (diff)
Fixed #21940 -- Added kwargs to contribute_to_class() of model fields..
Thanks Kronuz for the suggestion.
-rw-r--r--django/contrib/contenttypes/fields.py7
-rw-r--r--django/contrib/gis/db/models/fields.py4
-rw-r--r--django/db/models/fields/__init__.py8
-rw-r--r--django/db/models/fields/files.py8
-rw-r--r--django/db/models/fields/related.py4
-rw-r--r--django/db/models/fields/subclassing.py6
6 files changed, 19 insertions, 18 deletions
diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py
index a94ed3282c..3c3b4d0039 100644
--- a/django/contrib/contenttypes/fields.py
+++ b/django/contrib/contenttypes/fields.py
@@ -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
diff --git a/django/contrib/gis/db/models/fields.py b/django/contrib/gis/db/models/fields.py
index b71bba7725..6002f67ef3 100644
--- a/django/contrib/gis/db/models/fields.py
+++ b/django/contrib/gis/db/models/fields.py
@@ -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))
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 3e2c894a4d..3d8a5b79ad 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -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,
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index 518008b28d..cc2c5a7789 100644
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -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.
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 7d9c4f9fe8..e86522f340 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -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
diff --git a/django/db/models/fields/subclassing.py b/django/db/models/fields/subclassing.py
index 2faf56fc00..c87cc144d0 100644
--- a/django/db/models/fields/subclassing.py
+++ b/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