My question is very similar to this question: How to modify a queryset and save it as new objects?
Say my models has following fields:
class myModel(models.Model):
articleId = models.ForeignKey(otherModel)
myCounter = models.IntegerField
Now, say keeping the articleId as constant, I want to save multiple rows by varying myCounter. This is what I am trying to do:
for x in range(1, 5):
m = myModel()
m.articleId = otherModel.objects.get(pid="some constant")
m.myCounter = x
m.save()
m.id = None
As suggested by the above post (and similar others), I tried setting both 'id' and 'pk' as None. But nothing is helping.
This code is writing just one row in the database and is updating the value of myCounter. How do I commit 4 different rows?