Opened 19 years ago
Last modified 17 years ago
#3987 closed
ModelAdmin should allow for overriding of ForeignKey/ManyToMany options — at Version 5
| Reported by: | 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 )
See discussion in comments.
Change History (6)
by , 19 years ago
| Attachment: | customfilters.diff added |
|---|
comment:1 by , 19 years ago
| Has patch: | set |
|---|---|
| Patch needs improvement: | set |
comment:2 by , 19 years ago
| Triage Stage: | Unreviewed → Design decision needed |
|---|
comment:3 by , 18 years ago
| Version: | new-admin → SVN |
|---|
comment:4 by , 18 years ago
| Version: | SVN → newforms-admin |
|---|
comment:5 by , 18 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 needed → Accepted |
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.
the patch