Django

Code

Changeset 4881

Show
Ignore:
Timestamp:
03/31/07 07:02:37 (2 years ago)
Author:
mtredinnick
Message:

Fixed #2363 -- Improved base class checking in ModelBase? metaclass. Thanks to
combined work from phil.h.smith@gmail.com and Chris.Wesseling@cwi.nl.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/base.py

    r4609 r4881  
    2323    def __new__(cls, name, bases, attrs): 
    2424        # If this isn't a subclass of Model, don't do anything special. 
    25         if name == 'Model' or not filter(lambda b: issubclass(b, Model), bases): 
     25        try: 
     26            if not filter(lambda b: issubclass(b, Model), bases): 
     27                return super(ModelBase, cls).__new__(cls, name, bases, attrs) 
     28        except NameError: 
     29            # Model isn't defined yet, meaning we're looking at django's own Model defined below  
    2630            return super(ModelBase, cls).__new__(cls, name, bases, attrs) 
    2731 
  • django/trunk/tests/modeltests/invalid_models/models.py

    r3734 r4881  
    9898    m2m_4 = models.ManyToManyField('self', symmetrical=False) 
    9999 
     100class Model(models.Model): 
     101    "But it's valid to call a model Model." 
     102    year = models.PositiveIntegerField() #1960 
     103    make = models.CharField(maxlength=10) #Aston Martin 
     104    name = models.CharField(maxlength=10) #DB 4 GT 
     105 
     106class Car(models.Model): 
     107    colour = models.CharField(maxlength=5) 
     108    model = models.ForeignKey(Model) 
     109 
    100110model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute. 
    101111invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute.