kopia lustrzana https://github.com/wagtail/wagtail
Document ineffectiveness of specifying `Page._meta.ordering`
rodzic
fd821179cd
commit
db14a1dcf4
|
@ -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')
|
||||
|
|
Ładowanie…
Reference in New Issue