mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Used auto-numbered lists in documentation.
This commit is contained in:
committed by
Tim Graham
parent
cf915cb513
commit
9b15ff08ba
@@ -699,12 +699,12 @@ complex conversions between your Python types and your database and
|
||||
serialization formats. Here are a couple of tips to make things go more
|
||||
smoothly:
|
||||
|
||||
1. Look at the existing Django fields (in
|
||||
#. Look at the existing Django fields (in
|
||||
:file:`django/db/models/fields/__init__.py`) for inspiration. Try to find
|
||||
a field that's similar to what you want and extend it a little bit,
|
||||
instead of creating an entirely new field from scratch.
|
||||
|
||||
2. Put a ``__str__()`` method on the class you're wrapping up as a field. There
|
||||
#. Put a ``__str__()`` method on the class you're wrapping up as a field. There
|
||||
are a lot of places where the default behavior of the field code is to call
|
||||
``str()`` on the value. (In our examples in this document, ``value`` would
|
||||
be a ``Hand`` instance, not a ``HandField``). So if your ``__str__()``
|
||||
@@ -736,12 +736,12 @@ A few suggestions
|
||||
In addition to the above details, there are a few guidelines which can greatly
|
||||
improve the efficiency and readability of the field's code.
|
||||
|
||||
1. The source for Django's own ``ImageField`` (in
|
||||
#. The source for Django's own ``ImageField`` (in
|
||||
``django/db/models/fields/files.py``) is a great example of how to
|
||||
subclass ``FileField`` to support a particular type of file, as it
|
||||
incorporates all of the techniques described above.
|
||||
|
||||
2. Cache file attributes wherever possible. Since files may be stored in
|
||||
#. Cache file attributes wherever possible. Since files may be stored in
|
||||
remote storage systems, retrieving them may cost extra time, or even
|
||||
money, that isn't always necessary. Once a file is retrieved to obtain
|
||||
some data about its content, cache as much of that data as possible to
|
||||
|
||||
Reference in New Issue
Block a user