Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7621 -- Enable superclassing of the various metaclasses we use.

Also tidy up some initialisation code in django.db.models.base.ModelBase.
Thanks, Christian Tanzer.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7846 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0d0cbfd56ee468a50910d2e0686a0f28029992ba 1 parent e2740dd
Malcolm Tredinnick authored July 06, 2008
1  AUTHORS
@@ -350,6 +350,7 @@ answer newbie questions, and generally made Django that much better:
350 350
     Swaroop C H <http://www.swaroopch.info>
351 351
     Aaron Swartz <http://www.aaronsw.com/>
352 352
     Ville Säävuori <http://www.unessa.net/>
  353
+    Christian Tanzer <tanzer@swing.co.at>
353 354
     Tyler Tarabula <tyler.tarabula@gmail.com>
354 355
     Tyson Tate <tyson@fallingbullets.com>
355 356
     Frank Tegtmeyer <fte@fte.to>
14  django/db/models/base.py
@@ -31,19 +31,15 @@
31 31
 class ModelBase(type):
32 32
     "Metaclass for all models"
33 33
     def __new__(cls, name, bases, attrs):
34  
-        # If this isn't a subclass of Model, don't do anything special.
35  
-        try:
36  
-            parents = [b for b in bases if issubclass(b, Model)]
37  
-        except NameError:
38  
-            # 'Model' isn't defined yet, meaning we're looking at Django's own
39  
-            # Model class, defined below.
40  
-            parents = []
  34
+        super_new = super(ModelBase, cls).__new__
  35
+        parents = [b for b in bases if isinstance(b, ModelBase)]
41 36
         if not parents:
42  
-            return super(ModelBase, cls).__new__(cls, name, bases, attrs)
  37
+            # If this isn't a subclass of Model, don't do anything special.
  38
+            return super_new(cls, name, bases, attrs)
43 39
 
44 40
         # Create the class.
45 41
         module = attrs.pop('__module__')
46  
-        new_class = type.__new__(cls, name, bases, {'__module__': module})
  42
+        new_class = super_new(cls, name, bases, {'__module__': module})
47 43
         attr_meta = attrs.pop('Meta', None)
48 44
         abstract = getattr(attr_meta, 'abstract', False)
49 45
         if not attr_meta:
3  django/newforms/forms.py
@@ -56,7 +56,8 @@ class DeclarativeFieldsMetaclass(type):
56 56
     """
57 57
     def __new__(cls, name, bases, attrs):
58 58
         attrs['base_fields'] = get_declared_fields(bases, attrs)
59  
-        return type.__new__(cls, name, bases, attrs)
  59
+        return super(DeclarativeFieldsMetaclass,
  60
+                     cls).__new__(cls, name, bases, attrs)
60 61
 
61 62
 class BaseForm(StrAndUnicode):
62 63
     # This is the main implementation of all the Form logic. Note that this

0 notes on commit 0d0cbfd

Please sign in to comment.
Something went wrong with that request. Please try again.