Changes between Initial Version and Version 5 of Ticket #3987


Ignore:
Timestamp:
Jun 7, 2007, 5:39:44 PM (17 years ago)
Author:
Adrian Holovaty
Comment:

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)

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #3987

    • Property Has patch set
    • Property Patch needs improvement set
    • Property Triage Stage UnreviewedAccepted
    • Property Version new-adminnewforms-admin
    • Property Summary Customs filters for related keys in the admin (newforms-admin)ModelAdmin should allow for overriding of ForeignKey/ManyToMany options
  • Ticket #3987 – Description

    initial v5  
     1See discussion in comments.
Back to Top