class.txt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. =====================
  2. Model class reference
  3. =====================
  4. .. currentmodule:: django.db.models
  5. This document covers features of the :class:`~django.db.models.Model` class.
  6. For more information about models, see :doc:`the complete list of Model
  7. reference guides </ref/models/index>`.
  8. Attributes
  9. ==========
  10. ``objects``
  11. -----------
  12. .. attribute:: Model.objects
  13. Each non-abstract :class:`~django.db.models.Model` class must have a
  14. :class:`~django.db.models.Manager` instance added to it.
  15. Django ensures that in your model class you have at least a
  16. default ``Manager`` specified. If you don't add your own ``Manager``,
  17. Django will add an attribute ``objects`` containing default
  18. :class:`~django.db.models.Manager` instance. If you add your own
  19. :class:`~django.db.models.Manager` instance attribute, the default one does
  20. not appear. Consider the following example::
  21. from django.db import models
  22. class Person(models.Model):
  23. # Add manager with another name
  24. people = models.Manager()
  25. For more details on model managers see :doc:`Managers </topics/db/managers>`
  26. and :ref:`Retrieving objects <retrieving-objects>`.