Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#8292 closed (fixed)

InlineModelAdmin not honoring filter_horizontal

Reported by: dakrauth Owned by: brosner
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

One would expect the filter_horizontal / filter_vertical admin options to
function with the InlineModelAdmin classes for generic relationships
in contenttypes.generic.

Considering the code snippet below, I would have expected the nice javascript
dual-picklist interface instead of the plain, single multiselect input.

Sample models.py file:

from django.db import models 
from django.contrib.auth.models import User 
from django.contrib import admin 
from django.contrib.contenttypes import generic 
from django.contrib.contenttypes.models import ContentType 

class GenericDocument(models.Model): 
    title = models.CharField(max_length=100) 
    authors = models.ManyToManyField(User, blank=True) 
    content_type = models.ForeignKey(ContentType) 
    object_id = models.PositiveIntegerField() 
    content_object = generic.GenericForeignKey() 

class Publisher(models.Model): 
    name = models.CharField(max_length=50) 
    articles = generic.GenericRelation(GenericDocument) 

class GenericDocumentInline(generic.GenericStackedInline): 
    model = GenericDocument 
    filter_horizontal = ('authors', ) 

class PublisherAdmin(admin.ModelAdmin): 
    list_display = ('name', ) 
    inlines = [GenericDocumentInline] 

admin.site.register(Publisher, PublisherAdmin)

Attachments (0)

Change History (7)

comment:1 Changed 6 years ago by mtredinnick

  • milestone set to post-1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Someday/Maybe

Generic relations are normal fields on a number of levels and expecting them to be drop in replacements everywhere is a little optimistic. So it's not really "one would expect" as much as "one might hope this will work in the future". Postponing this to post-1.0, since it will be fully backwards compatible to add it then and too much work to do so right now.

comment:2 Changed 6 years ago by mtredinnick

  • Component changed from Uncategorized to Admin interface

comment:3 Changed 6 years ago by mtredinnick

  • milestone changed from post-1.0 to 1.0
  • Triage Stage changed from Someday/Maybe to Accepted

Hmm ... I see Brian considers this possible in scope for 1.0, so I'll leave it up to him to decide if we can get it done in time. Recategorising on those grounds.

comment:4 Changed 6 years ago by brosner

  • Owner changed from nobody to brosner
  • Status changed from new to assigned
  • Summary changed from GenericInlineModelAdmin not honoring filter_horizontal to InlineModelAdmin not honoring filter_horizontal

It turns out this is bit more than specially generic inlines. It applies to all inlines. Adjusting title to reflect that.

comment:5 Changed 6 years ago by brosner

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [8392]) Fixed #8292 -- Honor filter_horizontal and filter_vertical in inlines correctly. It now adds the right Javascript to handle them when they are the only ones on the page. Thanks dakrauth for the report.

comment:6 Changed 6 years ago by anonymous

I've a similiar model but instead of:

articles = generic.GenericRelation(GenericDocument) 

I've:

articles = models.ForeignKey(Document) 

and instead of:

class GenericDocumentInline(generic.GenericStackedInline):

I've:

class DocumentInline(admin.StackedInline):

Is there a way to get the javascript dual-picklist interface for authors through a ForeignKey?

Thanks.

comment:7 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.