My model
won't update after save()
is called in my view
. Looking into several places (here, here) didn't yield any answers for my case. My model
does contains a ManyToManyField
:
Model:
class Event(models.Model):
name = models.CharField(max_length=120)
date = models.DateTimeField(auto_now=False, auto_now_add=False)
attendees = models.ManyToManyField(Employee)
approval = models.ForeignKey(EventStatus, default=2)
def __unicode__(self):
return self.name
def approve_url(self):
return reverse("RGAU:EventApprove", kwargs={"id": self.id})
View:
def EventApprove(request, id=None, **kwargs):
instance = get_object_or_404(Event, id=id)
instance.approval.id = 3
instance.save()
messages.success(request, "Event Approved")
return redirect("RGAU:UserDashboard")
The goal is to have the Event
instance updated to "Approved" when a button is pushed on the webpage (hence the view EventApprove
).
instance.approval.id
is suppose to assign the correct approval status id
but the save is not committed.
What am I doing wrong?