#34789: Admin filter_horizontal shows item in "Chosen" column after being added
through a Foreign Key field of the same model.
-------------------------------+--------------------------------------
     Reporter:  devin13cox     |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  contrib.admin  |                  Version:  4.2
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  1              |                    UI/UX:  1
-------------------------------+--------------------------------------

Comment (by devin13cox):

 Replying to [comment:2 Natalia Bidart]:
 > Hello! Thank you for your report. Could you please post your admin.py
 definition as well as your models.py (reduced to this example)? So we can
 try to reproduce and triage accordingly. Thanks!

 Of course, here is the model (reduced to the example):


 {{{
 class Workflow(models.Model):
     initial = models.ForeignKey('workflow.State', blank=True, null=True,
 related_name="workflow_initial", on_delete=models.SET_NULL)

 class Transition(models.Model):
     source = models.ManyToManyField(State,
 related_name="transition_source")
     target = models.ForeignKey(State, related_name="transition_target",
 on_delete=models.CASCADE)

 class State(models.Model):
     label = models.CharField(max_length=255)
 }}}

 And the admin (also reduced):


 {{{
 class WorkflowAdmin(SortableAdminBase, admin.ModelAdmin):
     inlines = [TransitionInline, ]
     fieldsets = (
         (None, {
             'fields': ["initial"],
         }),
     )

 class TransitionInline(SortableStackedInline, admin.StackedInline):

     model = Transition
     extra = 0
     filter_horizontal = ['source']

     fieldsets = (
         (' ', {
             'classes': ('collapse',),
             'fields': ('source', 'target')
         }),
     )

 class StateAdmin(admin.ModelAdmin):
     fieldsets = (
             (None, {
                 'fields': ("label",),
             }),
         )
 }}}

 As you can see, the model of interest is Transition and in the admin
 console it is represented through as an inline for another model called
 Workflow. I tried to remove any extra information to avoid confusion (part
 of this removal was my_order fields in case there is confusion as to why
 Sortable is being used).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34789#comment:3>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018a1a44d889-9b165961-651c-4b81-8510-51f72c55cf3e-000000%40eu-central-1.amazonses.com.

Reply via email to