44
I have the following model:
class Ticket(models.Model):
title = models.CharField()
merged_to = models.ForeignKey("self", related_name='merger_ticket', null=True, blank=True)
looser_ticket = models.BooleanField(default=False)
There are couple of ways of manipulating the model:
First
ticket = Ticket.objects.get(pk=1)
ticket.title = "This is edit title"
ticket.merged_to_id = 2
ticket.looser_ticket = True
Second
ticket = Ticket.objects.get(pk=1)
setattr(ticket, "title", "Edit Title")
setattr(ticket, "merged_to_id", 2)
setattr(ticket, "looser_ticket", True)
When I was manipulating the stuff, in views for the boolean value updation the first method did not work, however the second method worked. What is the difference between using first and second, and when they should be used?
Thanks!