Code

Ticket #14705: failed_attempt

File failed_attempt, 2.9 KB (added by vanschelven, 3 years ago)
Line 
1diff -r 1a5661fe179d django/db/models/base.py
2--- a/django/db/models/base.py  Tue Nov 16 15:14:04 2010 +0000
3+++ b/django/db/models/base.py  Tue Nov 16 23:30:27 2010 +0100
4@@ -126,13 +126,14 @@
5         o2o_map = dict([(f.rel.to, f) for f in new_class._meta.local_fields
6                 if isinstance(f, OneToOneField)])
7 
8-        for base in parents:
9+        for creation_level, base in enumerate(parents):
10             original_base = base
11             if not hasattr(base, '_meta'):
12                 # Things without _meta aren't functional models, so they're
13                 # uninteresting parents.
14                 continue
15 
16+            new_class._meta.creation_level = creation_level + 1
17             parent_fields = base._meta.local_fields + base._meta.local_many_to_many
18             # Check for clashes between locally declared fields and those
19             # on the base classes (we cannot handle shadowed fields at the
20diff -r 1a5661fe179d django/db/models/fields/__init__.py
21--- a/django/db/models/fields/__init__.py       Tue Nov 16 15:14:04 2010 +0000
22+++ b/django/db/models/fields/__init__.py       Tue Nov 16 23:30:27 2010 +0100
23@@ -57,6 +57,7 @@
24     # The auto_creation_counter is used for fields that Django implicitly
25     # creates, creation_counter is used for all user-specified fields.
26     creation_counter = 0
27+    creation_level = 0
28     auto_creation_counter = -1
29     default_validators = [] # Default set of validators
30     default_error_messages = {
31@@ -121,7 +122,9 @@
32 
33     def __cmp__(self, other):
34         # This is needed because bisect does not take a comparison function.
35-        return cmp(self.creation_counter, other.creation_counter)
36+        if self.creation_counter <= -1 or other.creation_counter <= -1:
37+            return cmp(self.creation_counter, other.creation_counter)
38+        return cmp((self.creation_level, self.creation_counter), (other.creation_level, other.creation_counter))
39 
40     def __deepcopy__(self, memodict):
41         # We don't have to deepcopy very much here, since most things are not
42diff -r 1a5661fe179d django/db/models/options.py
43--- a/django/db/models/options.py       Tue Nov 16 15:14:04 2010 +0000
44+++ b/django/db/models/options.py       Tue Nov 16 23:30:27 2010 +0100
45@@ -27,6 +27,7 @@
46 class Options(object):
47     def __init__(self, meta, app_label=None):
48         self.local_fields, self.local_many_to_many = [], []
49+        self.creation_level = 0
50         self.virtual_fields = []
51         self.module_name, self.verbose_name = None, None
52         self.verbose_name_plural = None
53@@ -148,6 +149,7 @@
54         # the "creation_counter" attribute of the field.
55         # Move many-to-many related fields from self.fields into
56         # self.many_to_many.
57+        field.creation_level = self.creation_level
58         if field.rel and isinstance(field.rel, ManyToManyRel):
59             self.local_many_to_many.insert(bisect(self.local_many_to_many, field), field)
60             if hasattr(self, '_m2m_cache'):