Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/topics/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ And here is the equivalent class built using ``type()``:
Any Django model that can be defined in the normal fashion can be
made using ``type()``.

You can also define methods and inner classes this way:

.. code-block:: python

attrs = {
'name': models.CharField(max_length=32),
'__str__': lambda self: '<{}> {}'.format(self.id, self.name),
'Meta': type('Meta': (), {'ordering': '-id'}),
'__module__': 'myapp.models'
}

Django's model cache
--------------------
Expand Down