Django,从formset

时间:2017-03-27 19:21:06

标签: django django-forms django-admin

我已覆盖save_formset方法以从管理页面提取数据。这是我的代码的样子,

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 个答案:

答案 0 :(得分: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)