#12203: ManyToManyField with through model can't be used in admin
-------------------------------------+-------------------------------------
     Reporter:  David Gouldin        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  contrib.admin        |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  M2M, admin,          |             Triage Stage:  Accepted
  through, through_fields            |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Dmitry Mugtasimov):

 If you also waiting for the fix and have a simple through model for some
 reason you may use `auto_created = True` to trick Django Admin:


 {{{
 class JobTitleExperienceThrough(models.Model):
     title = models.ForeignKey('JobTitle', on_delete=models.CASCADE,
                               related_name='experiences_through')
     experience = models.ForeignKey('Experience', on_delete=models.CASCADE,
                                    related_name='titles_trough')

     class Meta:
         # TODO(dmu) MEDIUM: Remove `auto_created = True` after these
 issues are fixed:
         #                   https://code.djangoproject.com/ticket/12203
 and
         #                   https://github.com/django/django/pull/10829
         auto_created = True


 class JobTitle(models.Model):
     name = models.CharField(max_length=64)
     role = models.ForeignKey('JobRole', on_delete=models.CASCADE,
                              related_name='titles')
     experiences = models.ManyToManyField('Experience',
 through='JobTitleExperienceThrough',
                                          related_name='titles',
 blank=True)

     class Meta:
         ordering = ('id',)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/12203#comment:19>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.040446dfd919179ffa9ade462baad745%40djangoproject.com.

Reply via email to