我正在尝试将我的Django项目与Wagtail CMS集成在一起。在完成现有Django项目后,我正在尝试遵循this documentation。
完成此操作后,我可以在Wagtail上看到我的用户,但看不到我的应用程序。我是否需要其他步骤将现有的Django应用程序带入Wagtail?
我猜想的是,下面的两个代码段与其添加位置无关紧要。该文档说要添加它们而不指定确切的前后位置。
对于INSTALLED_APPS
@SpringBootApplication
@EnableBinding(Sink.class)
public class SampleReactiveConsumer {
public static void main(String[] args) {
SpringApplication.run(SampleReactiveConsumer.class,
"--spring.cloud.stream.function.definition=consume");
}
@Bean
public Consumer<Flux<String>> consume(){
return payloads -> payloads.flatMap(objectToSave -> reactiveMongoTemplate.insert(objectToSave)).subscribe();
}
}
对于MIDDLEWAR
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'modelcluster',
'taggit',
答案 0 :(得分:1)
正如 xyres
在评论中所述,我尝试遵循docs.wagtail.io/en/v2.4/reference/contrib/modeladmin。
正如文档所说明的,我做了以下工作:
在wagtail.contrib.modeladmin
中添加INSTALLED_APPS
。
settings.py
INSTALLED_APPS = [
...
'wagtail.contrib.modeladmin',
]
然后,我在Django应用程序下制作了一个名为wagtail_hooks.py
的文件,希望在Wagtail CMS中看到该文件,并将以下代码放入文件中。
wagtail_hooks.py
from wagtail.contrib.modeladmin.options import (
ModelAdmin, modeladmin_register)
from .models import Book
class BookAdmin(ModelAdmin):
model = Book
menu_label = 'Book' # ditch this to use verbose_name_plural from model
menu_icon = 'pilcrow' # change as required
menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
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', 'author')
list_filter = ('author',)
search_fields = ('title', 'author')
# Now you just need to register your customised ModelAdmin class with Wagtail
modeladmin_register(BookAdmin)
完成上述操作后,您将在Wagtail CMS中看到您的App模型。