Author: mtredinnick
Date: 2007-03-31 07:02:37 -0500 (Sat, 31 Mar 2007)
New Revision: 4881
Modified:
django/trunk/django/db/models/base.py
django/trunk/tests/modeltests/invalid_models/models.py
Log:
Fixed #2363 -- Improved base class checking in ModelBase metaclass. Thanks to
combined work from [EMAIL PROTECTED] and [EMAIL PROTECTED]
Modified: django/trunk/django/db/models/base.py
===================================================================
--- django/trunk/django/db/models/base.py 2007-03-31 11:45:24 UTC (rev
4880)
+++ django/trunk/django/db/models/base.py 2007-03-31 12:02:37 UTC (rev
4881)
@@ -22,7 +22,11 @@
"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.
Modified: django/trunk/tests/modeltests/invalid_models/models.py
===================================================================
--- django/trunk/tests/modeltests/invalid_models/models.py 2007-03-31
11:45:24 UTC (rev 4880)
+++ django/trunk/tests/modeltests/invalid_models/models.py 2007-03-31
12:02:37 UTC (rev 4881)
@@ -97,6 +97,16 @@
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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---