291 | | How did :class:`~django.contrib.sites.managers.CurrentSiteManager` know which |
292 | | field of ``Photo`` was the :class:`~django.contrib.sites.models.Site`? It |
293 | | defaults to looking for a field called |
294 | | :class:`~django.contrib.sites.models.Site`. If your model has a |
295 | | :class:`~django.db.models.fields.related.ForeignKey` or |
296 | | :class:`~django.db.models.fields.related.ManyToManyField` called something |
297 | | *other* than :class:`~django.contrib.sites.models.Site`, you need to explicitly |
298 | | pass that as the parameter to |
299 | | :class:`~django.contrib.sites.managers.CurrentSiteManager`. The following model, |
300 | | which has a field called ``publish_on``, demonstrates this:: |
| 291 | By default, :class:`~django.contrib.sites.managers.CurrentSiteManager` |
| 292 | looks for a either a :class:`~django.db.models.fields.related.ForeignKey` |
| 293 | called ``site`` or a :class:`~django.db.models.fields.related.ManyToManyField` |
| 294 | called ``sites`` to filter on. If you use a field named something other than |
| 295 | ``site`` or ``sites`` to identify which |
| 296 | :class:`~django.contrib.sites.models.Site` objects your object is related to, |
| 297 | then you need to explicitly pass the custom field name as a parameter to |
| 298 | :class:`~django.contrib.sites.managers.CurrentSiteManager` on your model. The |
| 299 | following model, which has a field called ``publish_on``, demonstrates this:: |
320 | | in the :ref:`manager documentation <topics-db-managers>`, if you define a manager |
321 | | manually, then Django won't create the automatic ``objects = models.Manager()`` |
322 | | manager for you.Also, note that certain parts of Django -- namely, the Django admin site and |
323 | | generic views -- use whichever manager is defined *first* in the model, so if |
324 | | you want your admin site to have access to all objects (not just site-specific |
325 | | ones), put ``objects = models.Manager()`` in your model, before you define |
| 319 | in the :ref:`manager documentation <topics-db-managers>`, if you define a |
| 320 | manager manually, then Django won't create the automatic |
| 321 | ``objects = models.Manager()`` manager for you. Also note that certain parts |
| 322 | of Django -- namely, the Django admin site and generic views -- use whichever |
| 323 | manager is defined *first* in the model, so if you want your admin site to |
| 324 | have access to all objects (not just site-specific ones), put |
| 325 | ``objects = models.Manager()`` in your model, before you define |