summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-03-31 12:02:37 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-03-31 12:02:37 +0000
commit1109e722aaf1c9100bcb4ea0c3e23b5fd4c8c8de (patch)
tree0f711d219f0aa227d5a338fbda4c917fda1dc8f7
parent04c155fd06484058d5677f61f6931f7f5da0922f (diff)
Fixed #2363 -- Improved base class checking in ModelBase metaclass. Thanks to
combined work from phil.h.smith@gmail.com and Chris.Wesseling@cwi.nl. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4881 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/base.py6
-rw-r--r--tests/modeltests/invalid_models/models.py10
2 files changed, 15 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index b70e6fd99a..8ec9018cee 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -22,7 +22,11 @@ class ModelBase(type):
"Metaclass for all models"
def __new__(cls, name, bases, attrs):
# If this isn't a subclass of Model, don't do anything special.
- if name == 'Model' or not filter(lambda b: issubclass(b, Model), bases):
+ try:
+ if not filter(lambda b: issubclass(b, Model), bases):
+ return super(ModelBase, cls).__new__(cls, name, bases, attrs)
+ except NameError:
+ # Model isn't defined yet, meaning we're looking at django's own Model defined below
return super(ModelBase, cls).__new__(cls, name, bases, attrs)
# Create the class.
diff --git a/tests/modeltests/invalid_models/models.py b/tests/modeltests/invalid_models/models.py
index 2299cd85e6..af54ec3d35 100644
--- a/tests/modeltests/invalid_models/models.py
+++ b/tests/modeltests/invalid_models/models.py
@@ -97,6 +97,16 @@ class SelfClashM2M(models.Model):
m2m_3 = models.ManyToManyField('self', symmetrical=False)
m2m_4 = models.ManyToManyField('self', symmetrical=False)
+class Model(models.Model):
+ "But it's valid to call a model Model."
+ year = models.PositiveIntegerField() #1960
+ make = models.CharField(maxlength=10) #Aston Martin
+ name = models.CharField(maxlength=10) #DB 4 GT
+
+class Car(models.Model):
+ colour = models.CharField(maxlength=5)
+ model = models.ForeignKey(Model)
+
model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute.
invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute.
invalid_models.fielderrors: "floatfield": FloatFields require a "max_digits" attribute.