2 개의 모델이있는 레스토랑 메뉴가 있습니다. A Product
모델 및 MenuSelection
모델. 제품은 많은 메뉴에 속할 수 있습니다. MenuSelection
은 인라인 관계로 Product
에 추가됩니다.Wagtail Snippets 인라인 오브젝트를 반복하십시오.
내가 겪고있는 도전 과제는 ModelAdmin
list_display
에 메뉴 개체를 나열하는 것입니다. ForeignKey 관계를 만들거나 Inline 객체를 반복하는 @property를 만들어야합니까? 나는 내 경험으로 다른 벽을 확실히 쳤다. 어떤 도움이라도 대단히 감사 할 것입니다.
MenuSelection에
class MenuSelection(ClusterableModel):
menu_section = models.CharField(default=None, max_length=100, choices=MENU_CHOICES, unique=True, verbose_name='Menu Section')
menu = models.CharField(default=None, max_length=100, choices=MENU, unique=True, verbose_name='Menu')
menu_price = models.DecimalField(
blank=True,
null=True,
max_digits=5,
decimal_places=2,
verbose_name='Menu Price',
help_text='Numbers only with 2 digital decimal. I.e. 25.00'
)
panels = [
MultiFieldPanel(
[
FieldPanel('menu'),
FieldPanel('menu_section'),
FieldPanel('menu_price'),
],
heading="Menu & Prices",
classname="collapsible"
),
]
제품
class ProductMenuPrices(Orderable, MenuSelection):
page = ParentalKey('Product', related_name='menu_selection')
@register_snippet
class Product(ClusterableModel):
product_title = models.CharField(max_length=255, verbose_name='Menu Item')
product_description = models.TextField(verbose_name='Product Description', blank=True)
panels = [
MultiFieldPanel(
[
FieldPanel('product_title'),
FieldPanel('product_description'),
InlinePanel('menu_selection', label="Menu & Price Assignment", max_num=3),
],
heading="Product Detail",
classname="collapsible"
),
]
class Meta:
verbose_name = 'Menu Item'
def __str__(self):
return self.product_title
ProductModelAdmin
class ProductModelAdmin(ModelAdmin):
model = Product
menu_label = 'Menu'
menu_icon = 'snippet'
menu_order = 300
add_to_settings_menu = False
exclude_from_explorer = False
list_display = ('product_title', 'product_description')
list_filter = 'product_title',
search_fields = 'product_title',
modeladmin_register(ProductModelAdmin)
wagtail admin에서 django admin 또는 about wagtail snippets에 관한 내용입니까? – dahrens
죄송합니다. 스 니펫으로 제작되고 있습니다. –