Document ineffectiveness of specifying `Page._meta.ordering`

pull/1676/head
Nick Smith 2015-09-11 16:36:56 +01:00
rodzic fd821179cd
commit db14a1dcf4
1 zmienionych plików z 21 dodań i 0 usunięć

Wyświetl plik

@ -77,3 +77,24 @@ Make your model names more friendly to users of Wagtail using Django's internal
verbose_name = "Homepage"
When users are given a choice of pages to create, the list of page types is generated by splitting your model names on each of their capital letters. Thus a ``HomePage`` model would be named "Home Page" which is a little clumsy. ``verbose_name`` as in the example above, would change this to read "Homepage" which is slightly more conventional.
Page QuerySet ordering
----------------------
``Page``-derived models *cannot* be given a default ordering by using the standard Django approach of adding an ``ordering`` attribute to the internal ``Meta`` class.
.. code-block:: python
class NewsItemPage(Page):
publication_date = models.DateField()
...
class Meta:
ordering = ('-publication_date', ) # will not work
This is because ``Page`` enforces ordering QuerySets by path. Instead you must apply the ordering explicitly when you construct a QuerySet:
.. code-block:: python
news_items = NewsItemPage.objects.live().order_by('-publication_date')