Code

Changes between Initial Version and Version 5 of Ticket #3987


Ignore:
Timestamp:
06/07/07 15:39:44 (7 years ago)
Author:
adrian
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 Patch needs improvement set
    • Property Needs tests unset
    • Property Summary changed from Customs filters for related keys in the admin (newforms-admin) to ModelAdmin should allow for overriding of ForeignKey/ManyToMany options
    • Property Version changed from new-admin to newforms-admin
    • Property Needs documentation unset
    • Property Has patch set
    • Property Triage Stage changed from Unreviewed to Accepted
  • Ticket #3987 – Description

    initial v5  
     1See discussion in comments.