Wagtail(Django) ModelAdmin 按钮视图操作
Wagtail(Django) ModelAdmin Button view action
我想在 wagtail admin 中放置一个按钮以在视图模式下进行检查,默认情况下会显示编辑和删除,但我不知道需要做什么才能调用仅包含模型视图的视图
这是我的代码:
products.models.py
class CamisaOrder(models.Model):
STATUS_CHOICES = (
('PAYMENTVERFICATION','Verificacion Forma Pago'), ('PROCESSINGORDER','Procesando Orden'),
('MAKING','Elaboracion'),
('PROCESSINGSHIPING','Preparando Envio'),
('SHIPPED','Enviado'),
('DELIVERED','Recibido'),
('CANCELED','Cancelado'),
('RETURNED','Retornado'),
)
camisa = models.ForeignKey('CamisetaProduct',related_name='+', on_delete= models.PROTECT)
cantidad = models.IntegerField()
status = models.CharField(max_length=20, null=False, blank=False, choices=STATUS_CHOICES, default="PROCESSINGORDER")
panels = [
FieldPanel('camisa'),
FieldPanel('cantidad'),
FieldPanel('status')
]
class Meta:
verbose_name="Camisa Orden"
verbose_name_plural="Camisas Ordenes"
wagtail_hooks.py
class ProductButtonHelper(ButtonHelper):
view_button_classnames = ['button-small', 'icon', 'icon-site']
def view_button(self, obj):
# Define a label for our button
text = 'View {}'.format(self.verbose_name)
logging.debug(obj)
return {
'url': #url here for inspect model#
'label': text,
'classname': self.finalise_classname(self.view_button_classnames),
'title': text,
}
def get_buttons_for_obj(self, obj, exclude=None, classnames_add=None, classnames_exclude=None):
btns = super().get_buttons_for_obj(obj, exclude, classnames_add, classnames_exclude)
if 'view' not in (exclude or []):
btns.append(
self.view_button(obj)
)
return btns
class CamisetaOrderAdmin(ModelAdmin):
model = CamisaOrder
button_helper_class = ProductButtonHelper
menu_label = 'Pedidos y Ordenes'
menu_icon = 'mail'
menu_order = 200
add_to_settings_menu = False
exclude_from_explorer = False
list_display = ('camisa', 'cantidad', 'status')
list_filter = ('status',)
search_fields = ( 'status',)
modeladmin_register(CamisetaOrderAdmin)
我如何实现这种方法?
我需要做一个自定义视图并插入 wagtail 管理模型,如果是这样的话,我该怎么做?我可以制作一个模型表单,如弹出窗口,显示模型的自定义操作吗?像改变他的状态或一些价值
我找到一个解决方案,在 ModelAdmin class
上添加 inspect_view_enabled
class CamisetaOrderAdmin(ModelAdmin):
model = CamisaOrder
# button_helper_class = ProductButtonHelper # ProductButtonHelper
# url_helper_class = CustomPageAdminURLHelper
menu_label = 'Pedidos y Ordenes'
menu_icon = 'mail'
menu_order = 200
add_to_settings_menu = False
exclude_from_explorer = False
list_display = ('camisa', 'cantidad', 'status')
list_filter = ('status',)
search_fields = ( 'status',)
inspect_view_enabled=True
inspect_view_fields = ('camisa', 'cantidad', 'status')
参考:https://docs.wagtail.io/en/stable/reference/contrib/modeladmin/inspectview.html
我想在 wagtail admin 中放置一个按钮以在视图模式下进行检查,默认情况下会显示编辑和删除,但我不知道需要做什么才能调用仅包含模型视图的视图
这是我的代码:
products.models.py
class CamisaOrder(models.Model):
STATUS_CHOICES = (
('PAYMENTVERFICATION','Verificacion Forma Pago'), ('PROCESSINGORDER','Procesando Orden'),
('MAKING','Elaboracion'),
('PROCESSINGSHIPING','Preparando Envio'),
('SHIPPED','Enviado'),
('DELIVERED','Recibido'),
('CANCELED','Cancelado'),
('RETURNED','Retornado'),
)
camisa = models.ForeignKey('CamisetaProduct',related_name='+', on_delete= models.PROTECT)
cantidad = models.IntegerField()
status = models.CharField(max_length=20, null=False, blank=False, choices=STATUS_CHOICES, default="PROCESSINGORDER")
panels = [
FieldPanel('camisa'),
FieldPanel('cantidad'),
FieldPanel('status')
]
class Meta:
verbose_name="Camisa Orden"
verbose_name_plural="Camisas Ordenes"
wagtail_hooks.py
class ProductButtonHelper(ButtonHelper):
view_button_classnames = ['button-small', 'icon', 'icon-site']
def view_button(self, obj):
# Define a label for our button
text = 'View {}'.format(self.verbose_name)
logging.debug(obj)
return {
'url': #url here for inspect model#
'label': text,
'classname': self.finalise_classname(self.view_button_classnames),
'title': text,
}
def get_buttons_for_obj(self, obj, exclude=None, classnames_add=None, classnames_exclude=None):
btns = super().get_buttons_for_obj(obj, exclude, classnames_add, classnames_exclude)
if 'view' not in (exclude or []):
btns.append(
self.view_button(obj)
)
return btns
class CamisetaOrderAdmin(ModelAdmin):
model = CamisaOrder
button_helper_class = ProductButtonHelper
menu_label = 'Pedidos y Ordenes'
menu_icon = 'mail'
menu_order = 200
add_to_settings_menu = False
exclude_from_explorer = False
list_display = ('camisa', 'cantidad', 'status')
list_filter = ('status',)
search_fields = ( 'status',)
modeladmin_register(CamisetaOrderAdmin)
我如何实现这种方法?
我需要做一个自定义视图并插入 wagtail 管理模型,如果是这样的话,我该怎么做?我可以制作一个模型表单,如弹出窗口,显示模型的自定义操作吗?像改变他的状态或一些价值
我找到一个解决方案,在 ModelAdmin class
上添加inspect_view_enabled
class CamisetaOrderAdmin(ModelAdmin):
model = CamisaOrder
# button_helper_class = ProductButtonHelper # ProductButtonHelper
# url_helper_class = CustomPageAdminURLHelper
menu_label = 'Pedidos y Ordenes'
menu_icon = 'mail'
menu_order = 200
add_to_settings_menu = False
exclude_from_explorer = False
list_display = ('camisa', 'cantidad', 'status')
list_filter = ('status',)
search_fields = ( 'status',)
inspect_view_enabled=True
inspect_view_fields = ('camisa', 'cantidad', 'status')
参考:https://docs.wagtail.io/en/stable/reference/contrib/modeladmin/inspectview.html