diff --git a/django/db/models/base.py b/django/db/models/base.py index 386986359d..bc41149a09 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import copy +import inspect import sys from functools import update_wrapper import warnings @@ -299,7 +300,8 @@ class ModelBase(type): cls.add_to_class(mgr_name, new_manager) 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) else: setattr(cls, name, value) diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py index 8a6e9c83b1..0222f9a3df 100644 --- a/tests/model_fields/models.py +++ b/tests/model_fields/models.py @@ -145,12 +145,22 @@ class VerboseNameField(models.Model): 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. class DecimalLessThanOne(models.Model): d = models.DecimalField(max_digits=3, decimal_places=3) +# See ticket #18389. +class FieldClassAttributeModel(models.Model): + field_class = models.CharField + +############################################################################### + + class DataModel(models.Model): short_data = models.BinaryField(max_length=10, default=b'\x08') data = models.BinaryField()