What I'm trying to do is create a preview of a flatpage that happens to include lists of items that we iterate over in a for loop to construct a table. We've used alter_flatpage to add the foreign key list.
We have a custom view that uses an extended flatpage form in order to grab the id numbers of these foreign keys.
What I want to do is this:
flatpage = extendedflatpageform.save(commit=False)
setattr(flatpage, tableitems, request.POST.getlist('tableitems'))
...
return render_to_response(flatpage.template_name, context_instance=ctx)开发者_如何学Python
The problem is this errors out due to flatpage being missing an id. If I do this:
flatpage = extendedflatpageform.save(commit=False)
flatpage.id = id # Got from view parameter, pulled out via urls
setattr(flatpage, tableitems, request.POST.getlist('tableitems'))
...
return render_to_response(flatpage.template_name, context_instance=ctx)
... then the object referred to by the id number gets modified. This is what I want to avoid.
Any suggestions would be appreciated.
精彩评论