3

模型.py:

class ExperienceSynopsis(Audit):
    user                    = models.ForeignKey(User, null = True, blank = True)
    area_skill              = models.CharField(max_length = 50, help_text = 'Example: Testing,Development,etc..')
    experience              = models.CharField(max_length = 50)

    def __unicode__(self):
        return self.area_skill

表格.py:

class ExperienceSynopsisForm(forms.Form):
    area_skill           = fields.CharField(max_length=50, help_text = 'Example: Testing,Development,etc..')
    experience           = fields.CharField(max_length=50)
ExperienceFormset = formsets.formset_factory(ExperienceSynopsisForm, formset = RequiredFormSet, extra = 0) 

我想在 admin.py 中添加表单集。如何为此模型启用管理员。请帮助我。

4

1 回答 1

5

Django 文档和教程为它的工作原理提供了先机

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.StackedInline

将你的 Formset 添加到你的 Inline 对象中,你就设置好了

class BookInline(admin.TabularInline):
    model = Book
    formset = # Yours

class AuthorAdmin(admin.ModelAdmin):
    inlines = [
        BookInline,
    ]

如果save_formset需要,用于覆盖保存

于 2012-06-11T11:55:55.683 回答