【发布时间】:2016-07-28 17:21:39
【问题描述】:
所以,我正在使用 Django Model Formsets。
首先,我使用 Django RestFramework 从我的 API 中获取内容:
itemsQuery = People.objects.using('api').prefetch_related('staff').filter(id__in=['293992'])
### I can dump itemsQuery and get a bunch of data that I need
### Ie: logger.error(itemsQuery.values()), so I know stuff is in there
然后,我尝试使用来自我的 API 的数据填充我的本地数据库,如下所示:
for people in itemsQuery:
allPeople = NewPeople.objects.update_or_create(
name=people.staff.name,
)
### I can dump the data out like so:
### logger.error(people.staff.name)
### and get a bunch of names, so I know that part is at least working
### and "name" is a field in my model
something = NewPeople.objects.filter(section_id__in=['293992'])
formset = PeopleFormSet(queryset=something)
context['formset'] = formset
return context
这是我的模板:
{% for form in formset %}
<div>first_name: {{ form.name.value }}</div>
{% endfor %}
但没有输出。空。
我是否错误地使用了 update_or_create?还有什么?
【问题讨论】:
标签: django django-forms modelform formset