diff --git a/doc/topics/model.rst b/doc/topics/model.rst index 37963c5..61811b9 100644 --- a/doc/topics/model.rst +++ b/doc/topics/model.rst @@ -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 --------------------