Code

Ticket #419: django-core-meta-__init__.py.diff

File django-core-meta-__init__.py.diff, 1.5 KB (added by eric@…, 9 years ago)

Proposed "no_table" patch to django/core/meta/init.py

Line 
1Index: django/core/meta/__init__.py
2===================================================================
3--- django/core/meta/__init__.py        (revision 955)
4+++ django/core/meta/__init__.py        (working copy)
5@@ -418,6 +418,11 @@
6         # attribute order.
7         fields.sort(lambda x, y: x.creation_counter - y.creation_counter)
8 
9+        # Should this class generate database tables (Default is Yes)?
10+        # This has the ultimate effect of keeping this class out of the _MODELS
11+        # list.
12+        create_table = not (meta_attrs.pop('no_table', False))
13+
14         # If this model is a subclass of another model, create an Options
15         # object by first copying the base class's _meta and then updating it
16         # with the overrides from this class.
17@@ -680,7 +685,9 @@
18             # contain this list:
19             # [<class 'django.models.polls.Poll'>, <class 'django.models.polls.Choice'>]
20             # Don't do this if replaces_module is set.
21-            app_package.__dict__.setdefault('_MODELS', []).append(new_class)
22+            # Exclude models where the user has set 'no_table = True'
23+            if create_table:
24+                app_package.__dict__.setdefault('_MODELS', []).append(new_class)
25 
26         # Cache the app label.
27         opts.app_label = app_label
28@@ -732,6 +739,7 @@
29     def __repr__(self):
30         return '<%s object>' % self.__class__.__name__
31 
32+
33 ############################################
34 # HELPER FUNCTIONS (CURRIED MODEL METHODS) #
35 ############################################