How to work with unsaved many-to-many relations in django?

前端 未结 3 1183
孤街浪徒
孤街浪徒 2021-01-12 23:51

I have a couple of models in django which are connected many-to-many. I want to create instances of these models in memory, present them to the user (via custom met

3条回答
  •  长发绾君心
    2021-01-13 00:10

    I would add a field which indicates whether the objects are "draft" or "live". That way they are persisted across requests, sessions, etc. and django stops complaining.

    You can then filter your objects to only show "live" objects in public views and only show "draft" objects to the user that created them. This can also be extended to allow "archived" objects (or any other state that makes sense).

提交回复
热议问题