Linked Questions
22 questions linked to/from How do I clone a Django model instance object and save it to the database?
6
votes
1
answer
13k
views
How to modify a queryset and save it as new objects?
I need to query for a set of objects for a particular Model, change a single attribute/column ("account"), and then save the entire queryset's objects as new objects/rows. In other words, I want to ...
18
votes
3
answers
3k
views
Clone an inherited django model instance
When I clone a django model instance I used to clean the 'pk' field.
This seems not to work with an inherited model :
Take this :
class ModelA(models.Model):
info1 = models.CharField(max_length=...
7
votes
1
answer
4k
views
How can I save the same form more than once in Django 1.8?
I have a model Product and a corresponding form Product and I need to update the stock with lets say 5 product, so I input the data for the Product and ask how many items of this product I want to ...
5
votes
2
answers
4k
views
Django: copy a model object using views and forms
I have a Django (1.8) model that has some class based generic views: list, update, delete, detail, create.
https://docs.djangoproject.com/en/1.8/ref/class-based-views/
On the detail or list view, I ...
5
votes
1
answer
2k
views
Django - how do I clone object without applying clone changes to source object
Best described by example:
View:
def my_view(request):
obj_old = Inventories.objects.get(id = source_id)
obj_new = obj_old
obj_old.some_field = 0
obj_old.save()
obj_new....
3
votes
2
answers
2k
views
django save form - overwrite old row
I have a form to add new data to my database, but this form overwrites the existing data in my table. I want to add a new tuple and keep old tuples in my database's table
forms.py
class StudentForm(...
2
votes
2
answers
2k
views
Insert multiple rows in one operation by cloning a queryset with only one column change in Django
I have seen the following link:
How do I clone a Django model instance object and save it to the database?
But this one does only 1 object cloning. What if I want to clone multiple objects cloned.
...
7
votes
1
answer
3k
views
Django maintain versions of a model object
I have a model Goal which has two M2M fields and is referred to by another model Event. Now, the requirement is such that Goal is editable which means I can add/delete from M2M fields and add/delete ...
1
vote
1
answer
885
views
copy database objects into another- django
I know how to copy python object in to another as,
new_obj.__dict__ = original_obj.__dict__.copy()
But while playing with database, it overwrite the old object with new one.
I know the old_obj is ...
1
vote
1
answer
1k
views
Better way to duplicate model instance and related model
I was searching for the fastest and simplest way to duplicate a model instance and related model. I found some techniques here and here but I think they are based on old django versions.
I have ...
1
vote
3
answers
1k
views
How Copy And Update A Function In Django Model
I have a BlogPost Model, and I want to define a copy function in it to copy all the posts and also all its comments.
Add to that; I need to update The time of the data_created as well.
Finally, It ...
1
vote
1
answer
541
views
How to duplicate a record with all dependencies?
In my Django app I have a model and there is another model that refers as Foreign key to my model.
For example:
Order - the parent model
Items - as a child in that order.
What is the easy way to ...
1
vote
2
answers
840
views
Create multiple identical objects from django form
What is the best way to go about creating multiple identical objects as a result of a user completing a single form in Django?
If I call form.save() in a loop (based on a set number, either set by ...
1
vote
1
answer
779
views
Django multi table inheritance: move instance between child models
Assume I have in models.pysomething like:
Class ModelA(models.Model):
# many fields, including
relatives = models.ManyToManyField(Person)
)
# also, A is foreign key to other models:
Class ...
1
vote
2
answers
721
views
Copy Django object and preserve model_set items
In my project, i have 2 models:
class Product(models.Model):
name = models.CharField(max_length=200)
class Material(models.Model):
name = models.CharField(max_length=200)
product = ...