2017-03-27 83 views
0

我重寫了save_formset方法從管理頁面提取數據。這裏是我的代碼看起來像,Django,從表單提取值

def save_formset(self, request, form, formset, change): 
    for f in formset: 
     print('Voter address is: ', f['voter_address']) 
    super().save_formset(request,form, formset, change) 

我得到的輸出

enter image description here

但我想提取的實際價值,這是「klncklas,」和第二個我想知道目前沒有價值。我如何實現這一目標?

回答

1
def save_formset(self, request, form, formset, change): 
    # Create instances. Each instance will be a "row" (obj) of the inline model 
    instances = formset.save(commit=False) 
    # Iterate over the instances (objects of the Inline Model) 
    for instance in instances: 
     # Get the object's attribute (Model field) 
     print(instance.voter_address) 
    super().save_formset(request,form, formset, change) 
+0

感謝很多朋友的工作我欣賞 –