gpt4 book ai didi

django admin 使用 formset

转载 作者:行者123 更新时间:2023-12-04 03:06:36 27 4
gpt4 key购买 nike

模型.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 中添加表单集。如何为此模型启用管理员。请帮助我。

最佳答案

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如果需要,覆盖保存

关于django admin 使用 formset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10979205/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com