I'm getting the error "Cannot set values on a ManyToManyField which
specifies an intermediary model." when I try to call form.save_m2m()
and I would appreciate any tips as to how to work around this.

Here's some code that illustrates what I am doing:

---
# Using a basic form in a view function:

ticket = form.save(commit=False)
ticket.save()
form.save_m2m() # this does not work

---
# in models.py:

class System(models.Model):
    # fields omitted for brevity

class Ticket(models.Model):
    systems = models.ManyToManyField(System, through='SystemTicket')

    def do_stuff(self):
        # Do some stuff that has to happen after m2m

# custom m2m so we can act on the post_save signal
class SystemTicket(models.Model):
    ticket = models.ForeignKey(Ticket)
    system = models.ForeignKey(System)

def update_stuff(instance, **kwargs):
    instance.ticket.do_stuff()
    instance.ticket.save()

post_save.connect(update_stuff, sender=SystemTicket)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to