Kaydet (Commit) 1be03aff authored tarafından Vlad Starostin's avatar Vlad Starostin Kaydeden (comit) Tim Graham

Fixed #18389 -- Fixed the way contribute_to_class is called

Now this method is only called only if the object is an instance.
This allows to have field classes as model class attributes.
üst ddd52b22
from __future__ import unicode_literals from __future__ import unicode_literals
import copy import copy
import inspect
import sys import sys
from functools import update_wrapper from functools import update_wrapper
import warnings import warnings
...@@ -299,7 +300,8 @@ class ModelBase(type): ...@@ -299,7 +300,8 @@ class ModelBase(type):
cls.add_to_class(mgr_name, new_manager) cls.add_to_class(mgr_name, new_manager)
def add_to_class(cls, name, value): def add_to_class(cls, name, value):
if hasattr(value, 'contribute_to_class'): # We should call the contirbute_to_class method only if it's bound
if not inspect.isclass(value) and hasattr(value, 'contribute_to_class'):
value.contribute_to_class(cls, name) value.contribute_to_class(cls, name)
else: else:
setattr(cls, name, value) setattr(cls, name, value)
......
...@@ -145,12 +145,22 @@ class VerboseNameField(models.Model): ...@@ -145,12 +145,22 @@ class VerboseNameField(models.Model):
field22 = models.URLField("verbose field22") field22 = models.URLField("verbose field22")
# This model isn't used in any test, just here to ensure it validates successfully. ###############################################################################
# These models aren't used in any test, just here to ensure they validate
# successfully.
# See ticket #16570. # See ticket #16570.
class DecimalLessThanOne(models.Model): class DecimalLessThanOne(models.Model):
d = models.DecimalField(max_digits=3, decimal_places=3) d = models.DecimalField(max_digits=3, decimal_places=3)
# See ticket #18389.
class FieldClassAttributeModel(models.Model):
field_class = models.CharField
###############################################################################
class DataModel(models.Model): class DataModel(models.Model):
short_data = models.BinaryField(max_length=10, default=b'\x08') short_data = models.BinaryField(max_length=10, default=b'\x08')
data = models.BinaryField() data = models.BinaryField()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment