I
I
ixotep2019-05-02 11:37:36
Django
ixotep, 2019-05-02 11:37:36

What is wrong with Wagtail CMS?

Hello! I'm trying to make an example from wagtail cms documentation but I get an error:

django.core.exceptions.FieldError: Cannot resolve keyword 'order' into field. Choices are: catalogindexpage, catalogpage, content_type

my model code:
from django.db import models
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.search import index


class CatalogIndexPage(Page):
    intro = RichTextField(blank=True)
    order = models.IntegerField('Порядок')

    def get_context(self, request, *args, **kwargs):
        context = super().get_context(request)
        catalog_pages = self.get_children().live().order_by('-order')
        context['catalog_pages'] = catalog_pages
        return context

    content_panels = Page.content_panels + [
        FieldPanel('intro', classname='full')
    ]

    class Meta:
        verbose_name = 'Главная страница каталога'


class CatalogPage(Page):
    # todo добавить поле превью картинки
    order = models.IntegerField(verbose_name='Порядок')
    intro = models.CharField(max_length=250)
    body = RichTextField(blank=True)
    price = models.IntegerField(verbose_name='Цена')

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('body'),
    ]

    content_panels = Page.content_panels + [
        FieldPanel('intro'),
        FieldPanel('body', classname='full'),
        FieldPanel('price'),
        FieldPanel('order'),
    ]

    class Meta:
        verbose_name = 'Проект'

the error itself occurs after adding the function:
def get_context(self, request, *args, **kwargs):
        context = super().get_context(request)
        catalog_pages = self.get_children().live().order_by('-order')
        context['catalog_pages'] = catalog_pages
        return context

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-05-02
@ixotep

.order_by('-catalogpage__order')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question