#29256: Needs two save() calls
-------------------------------------+-------------------------------------
Reporter: Victor | Owner: nobody
Porton |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
As http://guido.vonrudorff.de/django-manytomany-relationship-and-unsaved-
objects/ teaches (and our tests show too), `save()` should be called twice
when using m2m fields:
{{{
parts = BarClass.objects.filter(label__in=['eggs', 'bacon', 'spam'])
foo = FooClass(label='lunch')
foo.save() # do not forget this line
foo.child = parts
foo.save()
}}}
It looks silly and counter-intuitive to call `save()` twice. Is this a
bug?
At least the docs should say this vividly. So at very least we have a bug
in documentation for not addressing this issue.
The model code used:
{{{
class BarClass(models.Model):
label = models.CharField()
class FooClass(models.Model):
label = models.CharField()
child = models.ManyToManyField(BarClass)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29256>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.11a667fc1f65e27f87f85eecab60029b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.