I need to customise a through model of a many-to-many relationship, the customisation is subtle, because the user won't need do act manually, I try to explain myself better by explaining my use case with the following pseudo code:
RouterConfiguration
- vpn (many-to-many through VpnClient)
# other fields
VpnClient
- router: ForeignKey to RouterConfiguration
- vpn: ForeignKey to Vpn
- cert: ForeignKey to Cert
Vpn
# other fields
Cert
# (stores x509 certificates)
# other fields
The through model VpnClient
has only one additional field, a ForeignKey
to Cert
, but I want VpnClient
to automatically create a Cert
instance without user interaction and until here there is no problem.
The problem comes in the Django Admin, because as far as I understood, it is not possible to use the classic many2many widget when using a through model:
When you specify an intermediary model using the through argument to a
ManyToManyField
, the admin will not display a widget by default. This is because each instance of that intermediary model requires more information than could be displayed in a single widget, and the layout required for multiple widgets will vary depending on the intermediate model.
But I don't want the user to insert any extra information. I just want to be able to control the model so it can perform a series of actions automatically.
So my question is: is it possible to have the classic admin widget with a custom through model? If there's no easy solution maybe I could try with a custom widget? Or maybe there is an alternative way to accomplish what I need?
PS: apparently there's a ticket for this use case: https://code.djangoproject.com/ticket/12203