Django REST
- generic views - for example ListCreateAPIView
ORM = Object Relational Mapping
m2m_changed signal
Model instance methods
refresh_from_db()
>>> obj = MyModel.objects.first()
>>> del obj.field
>>> obj.field # Loads the field from the database
clean(), full_clean() - latter also checks for uniqueness constraint
Model Meta constraints
- UniqueConstraint, CheckConstraint
Meta options
- abstract
- managed (defaults to true) - tells Django to manage the database tables’
lifecycles; when set to False, Django won't create a DB table, etc.; useful when
the model represents an existing table created by other means
- ordering - the default ordering of the object
Proxy models
- useful in multi-table inheritance, where we don't want the child model to have
it's own table
- a proxy model can have e.g. a different ordering, so that you can query the same
table in two different orders, depending on which model you invoke
Differences between proxy inheritance and unmanaged models¶
1. If you are mirroring an existing model or database table and don’t want all the
original database table columns, use Meta.managed=False. That option is normally
useful for modeling database views and tables not under the control of Django.
2. If you are wanting to change the Python-only behavior of a model, but keep all
the same fields as in the original, use Meta.proxy=True. This sets things up so
that the proxy model is an exact copy of the storage structure of the original
model when data is saved.
DRF:
A Viewset groups multiple related actions together, handles different HTTP methods,
and often leverages automatic URL routing using routers.
Cursor pagination - only forward and backward controls
Filtering backend
Browsable API