Linked Questions

6 votes
1 answer
13k views

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 ...
B Robster's user avatar
  • 42.2k
18 votes
3 answers
3k views

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=...
Eric's user avatar
  • 5,139
7 votes
1 answer
4k views

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 ...
Crixx93's user avatar
  • 777
5 votes
2 answers
4k views

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 ...
43Tesseracts's user avatar
  • 4,987
5 votes
1 answer
2k views

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....
Edgar Navasardyan's user avatar
3 votes
2 answers
2k views

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(...
Arash Hatami's user avatar
  • 5,601
2 votes
2 answers
2k views

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. ...
Anuj's user avatar
  • 1,200
7 votes
1 answer
3k views

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 ...
Rajesh Yogeshwar's user avatar
1 vote
1 answer
885 views

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 ...
Nishant Nawarkhede's user avatar
1 vote
1 answer
1k views

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 ...
Below the Radar's user avatar
1 vote
3 answers
1k views

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 ...
Sina's user avatar
  • 55
1 vote
1 answer
541 views

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 ...
Ilya Bibik's user avatar
  • 4,134
1 vote
2 answers
840 views

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 ...
bodger's user avatar
  • 1,202
1 vote
1 answer
779 views

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 ...
Jakob's user avatar
  • 268
1 vote
2 answers
721 views

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 = ...
S.D.'s user avatar
  • 2,971

15 30 50 per page