问题
When editing a model field through Django Admin, I'm getting a [u'ManagementForm data is missing or has been tampered with']
validation error.
Steps:
- Edit a model through Django Admin and insert a special character (é,ñ)
- The data is saved OK.
- When editing again the model field (charField) the validation error is raised, whatever the input is.
When editing without special characters, the form is working ok.
Edit
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.
Relevant code:
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 Version: 1.4.21
Python Version: 2.7.9
回答1:
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.
The inlines didn't appear because there were errors in __unicode__
functions from the models.
Returning unicode type (python 2) in the __unicode__
function solved the issue.
来源:https://stackoverflow.com/questions/43923096/validationerror-umanagementform-data-is-missing-or-has-been-tampered-with-on