mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-17 04:10:24 +00:00
Merge pull request #48 from carljm/add-editorconfig-file
Add EditorConfig file
This commit is contained in:
commit
dae34efe10
2 changed files with 25 additions and 8 deletions
17
.editorconfig
Normal file
17
.editorconfig
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{py,rst,ini}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.yml]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
16
README.rst
16
README.rst
|
|
@ -115,7 +115,7 @@ default value to the first item in the ``STATUS`` choices:
|
|||
|
||||
from model_utils.fields import StatusField
|
||||
from model_utils import Choices
|
||||
|
||||
|
||||
class Article(models.Model):
|
||||
STATUS = Choices('draft', 'published')
|
||||
# ...
|
||||
|
|
@ -140,10 +140,10 @@ field changes:
|
|||
.. code-block:: python
|
||||
|
||||
from model_utils.fields import MonitorField, StatusField
|
||||
|
||||
|
||||
class Article(models.Model):
|
||||
STATUS = Choices('draft', 'published')
|
||||
|
||||
|
||||
status = StatusField()
|
||||
status_changed = MonitorField(monitor='status')
|
||||
|
||||
|
|
@ -247,18 +247,18 @@ 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()
|
||||
|
||||
|
|
@ -316,7 +316,7 @@ be returned as their actual type, you can pass subclass names to
|
|||
``get()`` method:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
place = Place.objects.get_subclass(id=some_id)
|
||||
# "place" will automatically be an instance of Place, Restaurant, or Bar
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue