我希望能夠編輯一個頁面上的所有數據。我怎樣才能做到這一點?我應該修改我的模型嗎?如果是這樣,那麼我應該如何修改它們?Django admin - 在同一頁上編輯父模型和相關模型
class TextStyle(models.Model):
color = models.CharField(_("color"), max_length=7)
style = models.CharField(_("style"), max_length=30)
typeface = models.CharField(_("typeface"), max_length=100)
class GenericText(models.Model):
text = models.TextField(_("text"))
lines = models.IntegerField(_("number of lines"))
style = models.ForeignKey(TextStyle, verbose_name=_('text style'), blank=False)
class ExpirationDate(models.Model):
date = models.DateField(_("date"))
style = models.ForeignKey(TextStyle, verbose_name=_('text style'), blank=False)
class Coupon(models.Model):
name = models.CharField(_("name"), max_length=100)
slug = AutoSlugField(populate_from="title")
background = models.ImageField(upload_to="userbackgrounds")
layout = models.ForeignKey(Layout, verbose_name=("layout"), blank=False)
logo = models.ImageField(upload_to="logos")
title = models.OneToOneField(GenericText, verbose_name=("title"), blank=False, related_name="coupon_by_title")
body = models.OneToOneField(GenericText, verbose_name=("body"), blank=False, related_name="coupon_by_body")
disclaimer = models.OneToOneField(GenericText, verbose_name=("disclaimer"), blank=False, related_name="coupon_by_disclaimer")
promo_code = models.OneToOneField(GenericText, verbose_name=("promo code"), blank=False, related_name="coupon_by_promo")
bar_code = models.OneToOneField(BarCode, verbose_name=("barcode"), blank=False, related_name="coupon_by_barcode")
expiration = models.OneToOneField(ExpirationDate, verbose_name=("expiration date"), blank=False, related_name="coupon_by_expiration")
is_template = models.BooleanField(verbose_name=("is a template"),)
category = models.ForeignKey(Category, verbose_name=("category"), blank=True,null=True, related_name="coupons")
user = models.ForeignKey(User, verbose_name=("user"), blank=False)
據我所知,Inline允許在子頁面上編輯父模型,但反之亦然(父子模型)。如果我錯了,你可以提供一個代碼,以允許什麼.. – 2010-06-27 23:36:00
德米特里,我認爲你是錯的。內聯允許您在父頁面上編輯兒童模型,但反之亦然。 – 2011-04-15 13:51:45
沒錯,InlineModelAdmin允許您將孩子編輯到對象更改頁面。 – 2011-11-09 08:07:56