ok i think this is very basic, but since I am new to Django I don't know how to handle this.
I need to copy an instance of a django-model. As explained here, there is a problem with copying ManyToMany relations. But the attachment "django-model-copying.diff" has that function I guess. So I don't know - does my Django already have that function? I don't know how to call it. Help would be appreciated.
There is no built-in method for copying model instances, it is possible to create new instance with all fields values copied. If an instance is saved with instance's pk set to None , the instance is used to create a new record in the DB. That means every field other than the PK is copied.
Django uses field class types to determine a few things: The column type, which tells the database what kind of data to store (e.g. INTEGER, VARCHAR, TEXT). The default HTML widget to use when rendering a form field (e.g. <input type=”text”>, <select>).
The docs include directions on how to do this - including how to handle many to many relationships.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With