English 中文(简体)
Django admin-Edit 母体模式和同一页的相关模式
原标题:Django admin - Edit parent model and related models on the same page

我想能够在一页上编辑所有数据。 如何做到这一点? 是否应当修改我的模式? 如果是的话,那么如何加以修改?

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)
问题回答

你们需要在你的行政工作中树立一个在线模式。 见:InlineModelAdmin

我建立了“一对一”关系在线断电模块,称为“反转ModelAdmin”。 您可找到here

您可以将其运用到您的科普翁实体,以便把所有“一对一”关系联系起来。

class CouponAdmin(ReverseModelAdmin):
    inline_type =  tabular 
admin.site.register(Coupon, CouponAdmin)

强制规定。 我不得不冒.到许多内部,以使它发挥作用,因此,解决办法是困难的,很容易打破。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签