Opened 11 years ago

Closed 11 years ago

#3978 closed (invalid)

Admin site : hide a ForeignKey field

Reported by: Baptiste <baptiste.goupil@…> 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: UI/UX:


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).

Change History (1)

comment:1 Changed 11 years ago by Baptiste <baptiste.goupil@…>

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top