2013-08-07 01:52:18 +00:00
|
|
|
Models
|
|
|
|
|
======
|
|
|
|
|
|
|
|
|
|
TimeFramedModel
|
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
An abstract base class for any model that expresses a time-range. Adds
|
|
|
|
|
``start`` and ``end`` nullable DateTimeFields, and a ``timeframed``
|
|
|
|
|
manager that returns only objects for whom the current date-time lies
|
|
|
|
|
within their time range.
|
|
|
|
|
|
|
|
|
|
|
2013-12-27 10:29:42 +00:00
|
|
|
TimeStampedModel
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
This abstract base class just provides self-updating ``created`` and
|
|
|
|
|
``modified`` fields on any model that inherits from it.
|
|
|
|
|
|
|
|
|
|
|
2013-08-07 01:52:18 +00:00
|
|
|
StatusModel
|
|
|
|
|
-----------
|
|
|
|
|
|
2013-08-07 03:47:22 +00:00
|
|
|
Pulls together :ref:`StatusField`, :ref:`MonitorField` and :ref:`QueryManager`
|
2013-08-07 01:52:18 +00:00
|
|
|
into an abstract base class for any model with a "status."
|
|
|
|
|
|
2013-08-07 03:47:22 +00:00
|
|
|
Just provide a ``STATUS`` class-attribute (a :ref:`Choices` object or a
|
2013-08-07 01:52:18 +00:00
|
|
|
list of two-tuples), and your model will have a ``status`` field with
|
|
|
|
|
those choices, a ``status_changed`` field containing the date-time the
|
|
|
|
|
``status`` was last changed, and a manager for each status that
|
|
|
|
|
returns objects with that status only:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from model_utils.models import StatusModel
|
|
|
|
|
from model_utils import Choices
|
|
|
|
|
|
|
|
|
|
class Article(StatusModel):
|
|
|
|
|
STATUS = Choices('draft', 'published')
|
|
|
|
|
|
|
|
|
|
# ...
|
|
|
|
|
|
|
|
|
|
a = Article()
|
|
|
|
|
a.status = Article.STATUS.published
|
|
|
|
|
|
|
|
|
|
# this save will update a.status_changed
|
|
|
|
|
a.save()
|
|
|
|
|
|
|
|
|
|
# this query will only return published articles:
|
|
|
|
|
Article.published.all()
|
2016-09-12 11:50:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
SoftDeletableModel
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
This abstract base class just provides field ``is_removed`` which is
|
|
|
|
|
set to True instead of removing the instance. Entities returned in
|
|
|
|
|
default manager are limited to not-deleted instances.
|
2019-02-26 16:34:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
UUIDModel
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
This abstract base class provides ``id`` field on any model that inherits from it
|
|
|
|
|
which will be the primary key.
|
|
|
|
|
|
|
|
|
|
If you dont want to set ``id`` as primary key or change the field name, you can be override it
|
2019-02-26 17:10:42 +00:00
|
|
|
with our `UUIDField`_
|
|
|
|
|
|
|
|
|
|
(https://github.com/jazzband/django-model-utils/blob/master/docs/fields.rst#uuidfield).
|
2019-02-26 16:34:20 +00:00
|
|
|
|
|
|
|
|
Also you can override the default uuid version. Versions 1,3,4 and 5 are now supported.
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from model_utils.models import UUIDModel
|
|
|
|
|
from model_utils import Choices
|
|
|
|
|
|
|
|
|
|
class MyAppModel(UUIDModel):
|
|
|
|
|
pass
|
|
|
|
|
|
2019-02-26 17:10:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _`UUIDField`: https://github.com/jazzband/django-model-utils/blob/master/docs/fields.rst#uuidfield
|