mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #3163 -- Add a "Meta.managed" option to models.
This allows a model to be defined which is not subject to database table creation and removal. Useful for models that sit over existing tables or database views. Thanks to Alexander Myodov, Wolfgang Kriesing and Ryan Kelly for the bulk of this patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10008 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
98710a5a28
commit
b4dd4d4bb7
9 changed files with 166 additions and 2 deletions
|
@ -431,6 +431,8 @@ Currently supported:
|
|||
* ``django`` for all ``*.py`` and ``*.html`` files (default)
|
||||
* ``djangojs`` for ``*.js`` files
|
||||
|
||||
.. _django-admin-reset:
|
||||
|
||||
reset <appname appname ...>
|
||||
---------------------------
|
||||
|
||||
|
@ -634,6 +636,8 @@ This command is disabled when the ``--settings`` option to
|
|||
situations, either omit the ``--settings`` option or unset
|
||||
``DJANGO_SETTINGS_MODULE``.
|
||||
|
||||
.. _django-admin-syncdb:
|
||||
|
||||
syncdb
|
||||
------
|
||||
|
||||
|
|
|
@ -75,6 +75,30 @@ Example::
|
|||
|
||||
See the docs for :meth:`~django.db.models.QuerySet.latest` for more.
|
||||
|
||||
``managed``
|
||||
-----------------------
|
||||
|
||||
.. attribute:: Options.managed
|
||||
|
||||
.. versionadded:: 1.1
|
||||
|
||||
If ``False``, no database table creation or deletion operations will be
|
||||
performed for this model. This is useful if the model represents an existing
|
||||
table or a database view that has been created by some other means.
|
||||
|
||||
The default value is ``True``, meaning Django will create the appropriate
|
||||
database tables in :ref:`django-admin-syncdb` and remove them as part of a
|
||||
:ref:`reset <django-admin-reset>` management command.
|
||||
|
||||
If a model contains a :class:`~django.db.models.ManyToManyField` and has
|
||||
``managed=False``, the intermediate table for the many-to-many join will also
|
||||
not be created. Should you require the intermediate table to be created, set
|
||||
it up as an explicit model and use the :attr:`ManyToManyField.through`
|
||||
attribute.
|
||||
|
||||
For tests involving models with ``managed=False``, it's up to you to ensure
|
||||
the correct tables are created as part of the test setup.
|
||||
|
||||
``order_with_respect_to``
|
||||
-------------------------
|
||||
|
||||
|
@ -181,3 +205,4 @@ The plural name for the object::
|
|||
verbose_name_plural = "stories"
|
||||
|
||||
If this isn't given, Django will use :attr:`~Options.verbose_name` + ``"s"``.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue