Opened 18 years ago

Last modified 16 years ago

#3987 closed

ModelAdmin should allow for overriding of ForeignKey/ManyToMany options — at Version 5

Reported by: Baptiste <baptiste.goupil@…> Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords: nfa-someday
Cc: brosner@…, Florian Apolloner, Martin Diers Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Adrian Holovaty)

See discussion in comments.

Change History (6)

by Baptiste <baptiste.goupil@…>, 18 years ago

Attachment: customfilters.diff added

the patch

comment:2 by Simon G. <dev@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:3 by Adrian Holovaty, 17 years ago

Version: new-adminSVN

comment:4 by Adrian Holovaty, 17 years ago

Version: SVNnewforms-admin

comment:5 by Adrian Holovaty, 17 years ago

Description: modified (diff)
Summary: Customs filters for related keys in the admin (newforms-admin)ModelAdmin should allow for overriding of ForeignKey/ManyToMany options
Triage Stage: Design decision neededAccepted

I like the idea, but the implementation is a bit brittle. What about adding method hooks on ModelAdmin that would allow you to specify the options for a given ForeignKey field? These methods could get passed the request object, so you could do per-user options. Something like this:

# Model

class Book(models.Model):
    title = models.CharField(maxlength=100)
    author = models.ForeignKey(Author)

# Admin

class BookAdmin(ModelAdmin):
    def dynamic_author_choices(self, request, book):
        # Default implementation:
        # return book.author_set.all()
        return book.author_set.filter(use_in_admin=True)
Note: See TracTickets for help on using tickets.
Back to Top