开发者

Making a preview of a django flatpage with foreign keys, allowing for changing what fks are included without altering the database

开发者 https://www.devze.com 2023-03-17 23:13 出处:网络
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 k

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消