#36468: Popup stays blank after adding a related object when filter_horizontal 
is
used
-------------------------------------+-------------------------------------
     Reporter:  Juan Rocha           |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.admin        |                  Version:  5.2
     Severity:  Normal               |               Resolution:
                                     |  worksforme
     Keywords:  filter_horizontal;   |             Triage Stage:
  SelectBox; add_to_cache;           |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Mark):

 Hello Natalia und Juan,

 I stumbled accross the same Problem, but the Example Juan suggested did
 not work for me either.

 In my case, the '+' Popup needs to be triggered from within an inline
 Form. A minimal Example would look like this



 Models:

 {{{
 from django.db import models


 class Book(models.Model):
     title = models.CharField()


 class Article(models.Model):
     title = models.CharField()
     books = models.ManyToManyField(Book, blank=True)


 class Author(models.Model):
     name = models.CharField()


 class Feature(models.Model):
     title = models.CharField()
     author = models.ForeignKey(Author, on_delete=models.CASCADE)
     article = models.ForeignKey(Article, on_delete=models.CASCADE)

 }}}

 Admin:

 {{{
 from django.contrib import admin

 from .models import Article, Author, Book, Feature



 class FeatureInline(admin.TabularInline):
     model = Feature


 @admin.register(Article)
 class ArticleAdmin(admin.ModelAdmin):
     inlines = [FeatureInline]
     filter_horizontal = ["books"]


 @admin.register(Author)
 class AuthorAdmin(admin.ModelAdmin):
     pass


 @admin.register(Book)
 class BookAdmin(admin.ModelAdmin):
     pass


 @admin.register(Feature)
 class FeatureAdmin(admin.ModelAdmin):
     pass

 }}}

 Trying to add an author in the Feature Inline will produce the bug
 described by Juan.

 A fix would be, to check, if the select input is managed by the SelectBox
 (~ it has been initialized) in RelatedObjectLookups.js (line 114)

 {{{
 if (window.SelectBox !== undefined && !SelectBox.cache[currentSelect.id]
 && SelectBox.cache[select.id]) {
 ...
 }
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36468#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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/010701998508452c-fe170f6f-a221-4b0d-abab-c7542a7afb14-000000%40eu-central-1.amazonses.com.

Reply via email to