Opened 18 years ago
Closed 18 years ago
#3978 closed (invalid)
Admin site : hide a ForeignKey field
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | new-admin |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you have a model with a ForeignKey that should not be editable by the user, you can try to do :
author = models.ForeignKey(User, editable=False)
But you will get "Key 'author' not found in Form" on /admin/blog/model/add/.
You can also specify the fields to display with the var "fields" of the Admin model and remove the author, but you will get "Key 'c' not found in Form" ('c' may vary).
So there is no way to hide this field (that I would like to assign without user's intervention in the method save_add).
Note:
See TracTickets
for help on using tickets.
The problem is more complicated.
The form is validated before save_add, so if the field is required, it can't work, and that can't be fixed unless by modifying lot of things. So I'll just say that user field may be blank, and I'll avoid that.