An abstract base class for any model that expresses a time-range. Adds
end nullable DateTimeFields, and a
manager that returns only objects for whom the current date-time lies
within their time range.
This abstract base class just provides self-updating
modified fields on any model that inherits from it.
Just provide a
STATUS class-attribute (a Choices object or a
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:
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()