所以,我正在使用Django Model Formsets。
首先,我使用Django RestFramework从我的API中获取内容:
function say(word) {
this.saying = word;
this.container = document.getElementById('result1');
return handleEvent.bind(this);
}
function shout(word) {
this.saying = word.toUpperCase();
this.container = document.getElementById('result2');
return handleEvent.bind(this);
}
function handleEvent() {
var text = document.createTextNode(this.saying);
this.container.innerHTML = '';
this.container.appendChild(text);
}
然后,我尝试用我的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
这是我的模板:
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
但没有输出。空。
我是否错误地使用了update_or_create?还有别的吗?
答案 0 :(得分:1)
您已使用name
创建了NewPeople对象;你还没有设置任何其他属性。但是当您获得something
查询集时,请按section_id
进行查询。你永远不会设置任何部分ID;这样查询将始终为空。