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

  • django/core/meta/__init__.py

     
    418418        # attribute order.
    419419        fields.sort(lambda x, y: x.creation_counter - y.creation_counter)
    420420
     421        # Should this class generate database tables (Default is Yes)?
     422        # This has the ultimate effect of keeping this class out of the _MODELS
     423        # list.
     424        create_table = not (meta_attrs.pop('no_table', False))
     425
    421426        # If this model is a subclass of another model, create an Options
    422427        # object by first copying the base class's _meta and then updating it
    423428        # with the overrides from this class.
     
    680685            # contain this list:
    681686            # [<class 'django.models.polls.Poll'>, <class 'django.models.polls.Choice'>]
    682687            # Don't do this if replaces_module is set.
    683             app_package.__dict__.setdefault('_MODELS', []).append(new_class)
     688            # Exclude models where the user has set 'no_table = True'
     689            if create_table:
     690                app_package.__dict__.setdefault('_MODELS', []).append(new_class)
    684691
    685692        # Cache the app label.
    686693        opts.app_label = app_label
     
    732739    def __repr__(self):
    733740        return '<%s object>' % self.__class__.__name__
    734741
     742
    735743############################################
    736744# HELPER FUNCTIONS (CURRIED MODEL METHODS) #
    737745############################################
Back to Top