#17528: Issue with m2m relations when need to prevent saving objects
-------------------------------------+-------------------------------------
     Reporter:  mmoya@…              |      Owner:  nobody
         Type:                       |     Status:  new
  Cleanup/optimization               |    Version:  1.3
    Component:  Database layer       |   Keywords:  m2m, related manager,
  (models, ORM)                      |  save
     Severity:  Normal               |  Has patch:  0
 Triage Stage:  Unreviewed           |      UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
 I think there are an inconsistency in the model's save method. Suppose we
 are editing an existing object from the admin.
 If I want to prevent saving objects (suppose I want to moderate the
 object), when I override the Model.save() or ModelAdmin.save_model()
 the m2m relations are also saved, but what I really want to do is avoid
 saving any changes.

 There is a simple example:

 {{{

 class Topping(models.Model):
     # ...

 class Pizza(models.Model):
     # ...
     toppings = models.ManyToManyField(Topping)

     def save(self, *args, **kwargs):
         return
 }}}


 This happens because the related m2m is commited outside the save method.
 If I execute this on shell:


 {{{
 >>> p = Pizza.objects.get(pk=5)
 >>> p.foo_field
 'Foo text'
 >>> t = Pizza.objects.get(pk=1)
 >>> p.foo_field = 'Bar text'
 >>> p.toppings.add(t)
 }}}


 Then, the p object have a new topping object added, but i never executed
 the p.save().

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17528>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to