我已覆盖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)
我输出为
但是我想提取实际值“klncklas”,而第二个我想知道没有价值存在。我怎么能做到这一点?
答案 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)