Wagtail中的非页面模型是否可以使用抽象基类?

时间:2018-11-29 01:46:30

标签: wagtail

我已经将一些非页面项建模为wagtail的子类,并一直将Page类作为我要完成的工作的一个很好的例子,但是实现有两个问题:

  1. 我希望能够在管理员中显示一个IndexView并显示项目列表,然后允许用户点击Add Item的方式进行操作Add Page在页面编辑器中,然后选择创建子项目。
  2. 我想使用InlinePanel,因此使用的是ParentalKey关系,但是在为此更改创建迁移时,makemigrations令人窒息。

models.py中:

@register_snippet
class Foo(ClusterableModel):
    title = models.CharField(max_length=100, blank=True, null=True)

    def name(self):
        return self.title

    class Meta:
        abstract = True

class Bar(Foo):
    description = models.CharField(max_length=100, blank=True, null=True)

class Baz(Foo):
    pass

class Foofriends(Orderable):
    name = models.CharField(max_length=10, blank=True, null=True)
    friends = ParentalKey('appname.Foo', on_delete=models.CASCADE, related_name='foo_friends')

,然后在wagtail_hooks.py中:

class FooAdmin(ModelAdmin):
    model = Foo
    menu_icon = 'date'
    add_to_settings_menu = False  # or True to add your model to the Settings sub-menu
    exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
    list_display = ('title',)
    search_fields = ('title',)

modeladmin_register(FooAdmin)
  1. 管理员不起作用-modeladmin中没有任何显示,当我尝试从管理员的代码段中进行编辑时,我收到404。

  2. 当我尝试为ParentalKey关系创建Foofriends迁移时,出现以下错误:

  

appname.Foofriends.friends:(fields.E300)字段定义关系   型号“ appname.Foo”(未安装或已安装)   抽象。 appname.Foofriends.friends :(字段E307)字段   appname.Foofriends.friends被声明为带有懒惰引用   'appname.foo',但应用程序'appname'不提供模型'foo'。

第一个问题的解决方法可能只是针对所有特定类分别注册管理员,这虽然不理想,但可行,但这无法解决第二个问题。

这有可能吗?有更好的方法吗?

0 个答案:

没有答案
相关问题