gpt4 book ai didi

Django 管理错误 ValidationError : [u'ManagementForm data is missing or has been tampered with']

转载 作者:行者123 更新时间:2023-12-05 08:12:58 25 4
gpt4 key购买 nike

您好,我正在创建一个带有动态内联的模型管理员。

class InlineProfile(admin.TabularInline):
model = Profile
# max_num = 1

class InlineProfileOne(admin.TabularInline):
model = TableOne
# max_num = 1

class InlineProfileTwo(admin.TabularInline):
model = TableTwo
# max_num = 1

class UserDisplay(admin.ModelAdmin):
inlines = [InlineProfile]

def get_inline_instances(self, request, obj=None):
up=UserProfile.objects.get(pk=obj.id)
if (up.job_type.job_type==1):
self.inlines.append(InlineProfileOne)
elif (up.job_type.job_type==2):
self.inlines.append(InlineProfileTwo)
return obj and super(UserDisplay, self).get_inline_instances(request, obj) or []

# def get_formsets(self, request, obj):
# print obj
# for inline in self.get_inline_instances(request, obj):
# yield inline.get_formset(request, obj)

list_display = [f.name for f in LCUser._meta.fields]
field_set = list(list_display)
field_set.remove('id')
field_set.remove('api_key')
field_set.remove('api_secret')

readonly_fields=['last_login_ip','last_login_timestamp','created_at','updated_at']

fieldsets = (
(None, {
'fields': field_set,

}),
('Advanced options', {
'classes': ('collapse',),
'fields': ('api_key', 'api_secret'),
}),
)

search_fields=list_display
list_filter=['user_type','profile_complete']
list_editable=list(list_display)
list_editable.remove('id')
list_editable.remove('updated_at')
list_editable.remove('created_at')
list_editable.remove('last_login_timestamp')
list_editable.remove('last_login_ip')

class Meta:
model = LCUser

在显示时,我有时会看到两行而不是一行,当我尝试更新它时,我得到“ManagementForm 数据丢失或已被篡改”

最佳答案

找出我做错了什么。看起来我忘了初始化 inlinse 变量。因此,每次我单击一个对象时,它都会再次添加相同的内联模型,这会在我尝试保存它时导致错误。

关于Django 管理错误 ValidationError : [u'ManagementForm data is missing or has been tampered with'],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37477075/

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