python - Django: How do I update previously created database entries? -
i've got bunch of created database entries of model class created, called equations. created new type of model, equationgroup, , want able link existing equations in database newly created equationgroups. how that?
update: forgot mention i've got foreignkey relationship in equation equationgroup. here short version of models.py
class equationgroup(models.model): name = models.charfield(max_length=50) def __str__(self): homecoming self.name class equation(models.model): name = models.charfield(max_length=50, null=false, blank=false) grouping = models.foreignkey(equationgroup)
you can create script goes through equations , attaches them equations groups. using equations.objects.all() can iterable of of equations objects. can go through in loop , assign each 1 specified equations group.
example:
for equation in using equations.objects.all(): equation.equationgroup = some_group #based on specify goes in group. equation.save()
python database django
No comments:
Post a Comment