Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7881 closed (fixed)

raw_id_fields and limit_choices_to with an __in query results in no output in popup list

Reported by: Matthew Flanagan <mattimustang@…> Owned by: jamesturk
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Here is a contrived example:

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

class Book(models.Model):
    name = models.Charfield(max_length=64)
    author = models.ForeignKey(Author, limit_choices_to = {'name__in': ('Oscar','Hugo')})

class AuthorAdmin(admin.ModelAdmin):
    pass

class BookAdmin(admin.ModelAdmin):
    raw_id_fields = ('author',)

admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)
>>> from models import Author
>>> Author.objects.create(name='Oscar')
>>> Author.objects.create(name='Matthew')
>>> Author.objects.create(name='Hugo')

Now in the Admin when editing a Book if I click on the magnifying glass to select an Author then the list in the popup is empty. If I change BookAdmin to be:

class BookAdmin(admin.ModelAdmin):
    pass

then the select drop down lists the right options.

Attachments (1)

raw_id_limit_choices_admin.diff (1.3 KB) - added by jamesturk 6 years ago.
small patches admin/views/main.py and admin/widgets.py fix this issue

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by jamesturk

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jamesturk
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

Changed 6 years ago by jamesturk

small patches admin/views/main.py and admin/widgets.py fix this issue

comment:2 Changed 6 years ago by jamesturk

  • Has patch set

comment:3 Changed 6 years ago by brosner

  • milestone changed from 1.0 beta to 1.0

comment:4 Changed 6 years ago by msaelices

@jacob, is this ticket fixed in [8700] ??

comment:5 Changed 6 years ago by jacob

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

comment:6 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.