https://learnwagtail.com/tutorials/how-register-django-model-wagtails-modeladmin/
https://www.revsys.com/tidbits/how-add-django-models-wagtail-admin/
Admin Page 메뉴에 모델을 추가해보려고 한다.
1. 모델 작성
user_management/models.py
# 공지사항
class Notice(models.Model):
type = models.CharField(blank=False, null=True, verbose_name="공지사항 종류", max_length=20)
title = models.CharField(blank=False, null=True, verbose_name="공지사항 제목", max_length=100)
content = RichTextField(blank=False, verbose_name="공지사항 내용")
def __str__(self):
return self.title
class Meta:
verbose_name_plural = "공지사항"
공지사항 모델을 Admin Page 메뉴에 추가 시켜보자.
2. admin.py 작성
user_management/admin.py
from wagtail.contrib.modeladmin.options import (
ModelAdmin,
modeladmin_register
)
from .models import Notice
# Register your models here.
class NoticeAdmin(ModelAdmin):
model = Notice
menu_label = "공지사항"
menu_icon = "placeholder"
menu_order = 290
add_to_settings_menu = False
exclude_from_explorer = False
list_display = ("type", "title")
search_fields = ("type", "title")
modeladmin_register(NoticeAdmin)
Wagtail Document
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)
위에 코드는 직접 작성한 ModelAdmin이고 아래는 Wagtail 공식문서이다. 관련 기능은 옆에 설명이 되어있다.
3. settings.py 등록
settings/base.py
INSTALLED_APPS = [
'wagtail.contrib.modeladmin',
]
model admin을 등록시켜주면 완료이다.
정상적으로 적용되었다.
'Back-End > Wagtail, Django' 카테고리의 다른 글
Wagtail Form (0) | 2021.11.02 |
---|---|
Wagtail Ajax (0) | 2021.10.29 |
Wagtail StreamField Queryset (0) | 2021.10.27 |
알아두면 좋을 것들 (0) | 2021.10.22 |
Wagtail StyleGuide + 추가 모듈 (0) | 2021.10.18 |