I have a very complex Model for a StitchTechnique. I would like to offer the possibility to create a new object by modifying an existing instance. I have a view which has 2 different submit buttons. one is to update existing object, the other one is to save the object as a new one.
I have used the updateView and pass it the instance of the object to edit. I have a set of related modelForms and formsets which correspond to the Model for a stitchtechnique. I have automatic generation of id_field.
I have noticed that there is a save_as_new argument for InLineFormsets which seems to correspond to what I need. But is does not exist for Model form. SO I suspect I must handle it in my code. Should I just ignore the id in the post data and also all foreign key fields and just set them to None?
Thanks for your answer. But this relates to the model. My question is about the form. Because the get creates a form with an instance keyword arguments id fields etc are present in the post data. So I believe I must erase some of those data in the post or probably better ignore some fields in the form cleaning. AN my question is which fields should I ignore. I suspect id and all relation fields should be ignored in the form fields cleaning. But I would appreciate having confirmation form experts.
I think you should let Django ORM handle duplication. Manually modifying ID or foreign keys in POST data is risky and can break relationships between models and formsets.