Answer the question
In order to leave comments, you need to log in
How to use getattr/setattr in .update() request in django?
There is a design:
rewarded_parents_fields = ('first_parent_rewarded',
'second_parent_rewarded',
'third_parent_rewarded',
'fourth_parent_rewarded', )
def pay_to_parent(self, line, five_per_period):
...
if line == 1:
TreeNode.objects.filter(id=self.id).update(first_parent_rewarded=True)
elif line == 2:
TreeNode.objects.filter(id=self.id).update(second_parent_rewarded=True)
elif line == 3:
TreeNode.objects.filter(id=self.id).update(third_parent_rewarded=True)
elif line == 4:
TreeNode.objects.filter(id=self.id).update(fourth_parent_rewarded=True)
Answer the question
In order to leave comments, you need to log in
Let's say like this.
TreeNode.objects.filter(id=self.id).update(**{rewarded_parents_fields[line - 1]: True})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question