2015-09-24 63 views
0

當打保存在模型編輯頁面上的管理員我得到這個回溯:Django管理ValidationError上的保存與內聯

Traceback (most recent call last): 
File "lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response 
    response = wrapped_callback(request, *callback_args, **callback_kwargs) 
File "lib/python2.7/site-packages/django/contrib/admin/options.py", line 616, in wrapper 
    return self.admin_site.admin_view(view)(*args, **kwargs) 
File "lib/python2.7/site-packages/django/utils/decorators.py", line 110, in _wrapped_view 
    response = view_func(request, *args, **kwargs) 
File "lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func 
    response = view_func(request, *args, **kwargs) 
File "lib/python2.7/site-packages/django/contrib/admin/sites.py", line 233, in inner 
    return view(request, *args, **kwargs) 
File "lib/python2.7/site-packages/django/contrib/admin/options.py", line 1519, in change_view 
    return self.changeform_view(request, object_id, form_url, extra_context) 
File "lib/python2.7/site-packages/django/utils/decorators.py", line 34, in _wrapper 
    return bound_func(*args, **kwargs) 
File "lib/python2.7/site-packages/django/utils/decorators.py", line 110, in _wrapped_view 
    response = view_func(request, *args, **kwargs) 
File "lib/python2.7/site-packages/django/utils/decorators.py", line 30, in bound_func 
    return func.__get__(self, type(self))(*args2, **kwargs2) 
File "lib/python2.7/site-packages/django/utils/decorators.py", line 145, in inner 
    return func(*args, **kwargs) 
File "lib/python2.7/site-packages/django/contrib/admin/options.py", line 1466, in changeform_view 
    if all_valid(formsets) and form_validated: 
File "lib/python2.7/site-packages/django/forms/formsets.py", line 439, in all_valid 
    if not formset.is_valid(): 
File "lib/python2.7/site-packages/django/forms/formsets.py", line 304, in is_valid 
    self.errors 
File "lib/python2.7/site-packages/django/forms/formsets.py", line 278, in errors 
    self.full_clean() 
File "lib/python2.7/site-packages/django/forms/formsets.py", line 325, in full_clean 
    for i in range(0, self.total_form_count()): 
File "lib/python2.7/site-packages/django/forms/formsets.py", line 115, in total_form_count 
    return min(self.management_form.cleaned_data[TOTAL_FORM_COUNT], self.absolute_max) 
File "lib/python2.7/site-packages/django/forms/formsets.py", line 97, in management_form 
    code='missing_management_form', 
ValidationError: [u'I dati del ManagementForm sono mancanti oppure sono stati manomessi’] 

在意大利的錯誤信息讀取

ManagementForm數據丟失或已被篡改

我還注意到POST請求包含一個額外的部分與前綴中的姓名和空ID,看起來可疑:

------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="csrfmiddlewaretoken" 

abcdef 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-TOTAL_FORMS" 

41 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-INITIAL_FORMS" 

41 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-MIN_NUM_FORMS" 

0 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-MAX_NUM_FORMS" 

1000 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-0-id" 

405718 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-0-property」 

87462 

[...] 

------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-40-id" 

462250 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-40-property" 

87462 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-__prefix__-id" 


------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="model_set-__prefix__-property" 

87462 
------WebKitFormBoundaryHni3TflxO2xxoMnc 
Content-Disposition: form-data; name="_save" 

Salva 
------WebKitFormBoundaryHni3TflxO2xxoMnc-- 

Django Inline Admin Formset extra entry has prefix instead of number 提示顯示:無不是從forms.css(空窗體類)上升,但在我的情況下,它似乎是。我正在查看Chrome開發人員工具。

我的內聯函數的定義如下:

class ModelInline1(admin.TabularInline): 
    model = Model1 
    show_change_link = True 
    can_delete = False 
    extra = 0 
    fields = ['created', 'type', 'formatted_text', 
       'picture_tag', 'from_seller', 'is_payment'] 
    readonly_fields = ['created', 'type', 'formatted_text', 
         'picture_tag', 'from_seller', 'is_payment'] 

class ModelInline2(admin.TabularInline): 
    model = Model2 
    show_change_link = True 
    extra = 0 
    fields = ['created', 'place', 'status', 'code'] 
    readonly_fields = ['created', 'place', 'status', 'code'] 

@admin.register(models.Conversation) 
class ModelAdmin(FSMTransitionMixin, admin.ModelAdmin): 
    fsm_field = ['status'] 
    list_display = ['id', 'buyer', 'item', 'status', 'last_message', 'created'] 
    list_filter = ['status', 'created'] 
    fields = ['status', 'created', 'last_message', 'tracking_number'] 
    readonly_fields = ['status', 'created', 'last_message', 'tracking_number'] 
    inlines = [ModelInline1, ModelInline2] 
    ordering = ['-created'] 
    search_fields = [ 
     'id', 
     'buyer__username', 
     'item__name', 
     'item__user__username' 
    ] 
+0

您還有自定義表單嗎?發佈完整的管理代碼 –

+0

我添加了管理代碼,沒有自定義表單。 –

+0

那麼ManagementForm從哪裏來? –

回答

1

錯誤是基本上是這樣Django admin: missing inlines for some records。 我沒有注意到第二行內容完全丟失。當內聯中使用的模型的__unicode__方法產生錯誤時,會發生這種情況。不幸的是,在這種情況下,管理員在沒有渲染內聯的情況下會自動失敗,但保存表單失敗,出現ValidationError