仅在特殊情况下,ValidationError [u'ManagementForm数据丢失或已被篡改'] [英] ValidationError [u'ManagementForm data is missing or has been tampered with'] only in special cases

查看:35
本文介绍了仅在特殊情况下,ValidationError [u'ManagementForm数据丢失或已被篡改']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Django Admin编辑模型字段时,出现 [u'ManagementForm数据丢失或已被篡改'] 验证错误.

When editing a model field through Django Admin, I'm getting a [u'ManagementForm data is missing or has been tampered with'] validation error.

步骤:

  • 通过Django Admin编辑模型并插入特殊字符(é,ñ)
  • 数据保存成功.
  • 再次编辑模型字段时(charField)不管输入什么,都会引发验证错误.

在不使用特殊字符进行编辑的情况下,表单可以正常工作.

When editing without special characters, the form is working ok.

修改

保存特殊字符时,该模型的内联不会出现在编辑部分,因此在这种情况下验证错误是正确的.

When saving a special character, the inlines for that model doesn't show up in the edit section, so the validation error is correct in that case.

相关代码:

class StreamInline(admin.TabularInline):
    model = Stream
    form = StreamForm
    extra = 0
    #define order
    fields = ('name', 'canal', 'tipo', 'stream_type',
              'unit', 'formula', 'label', 'color',
              ('min_scale', 'max_scale', 'fixed_scale'), 'enabled')
    readonly_fields = ['name', 'stream_type']
    can_delete = False

    class Media:
        js = ('js/jquery-1.7.2.min.js', 'js/jscolor.min.js',)


class NodeAdmin(admin.ModelAdmin):
    search_fields = ['name', ]

    fields = (('identifier', 'name', 'node_type'), ('group','cultivation') , ('longitude', 'latitude','operator','sim_card','telephone'), 'config', ('enabled', 'deleted'),('date_node','date_bat','reference_irrig_date'),'notes')
    list_display = ['identifier', 'name', 'group', 'sim_card']
    list_filter = ('group__name',)

    #form = NodeForm

    #list_filter = ['deleted', 'enabled', 'node_type']
    inlines = [StreamInline]

Django版本:1.4.21

Django Version: 1.4.21

Python版本:2.7.9

Python Version: 2.7.9

推荐答案

错误: [u'ManagementForm数据丢失或已被篡改'] 是因为未显示内联,因此MAX_TOTAL_FORMS和其他的不一致.

The error: [u'ManagementForm data is missing or has been tampered with'] was because the inlines doesn't appear, so the MAX_TOTAL_FORMS and others doesn't concord.

因为模型中的 __ unicode __ 函数存在错误,所以没有显示内联.

The inlines didn't appear because there were errors in __unicode__ functions from the models.

__ unicode __ 函数中返回unicode类型(python 2)解决了该问题.

Returning unicode type (python 2) in the __unicode__ function solved the issue.

这篇关于仅在特殊情况下,ValidationError [u'ManagementForm数据丢失或已被篡改']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆