I am trying to make custom form for a model in the django admin area with a select field that is created on submit based on the request.user. The user would then pick from the select and it would save specific settings to the model.
the model:
class Thing1(models.Model):
user = models.ForeignKey(User)
setting_1 = models.BooleanField(default=False)
setting_2 = models.BooleanField(default=False)
setting_3 = models.BooleanField(default=False)
But instead of having the user set the settings fields manually, I'd like to display a Select with something like:
- Default Settings
- Other Settings
And the user would select one and the system would save the settings booleans accordingly. The actual options of the select depends on the user, so I need request.user to be able to build that select field. I don't seem to have access to request in the ModelForm.
So I know that I can exclude the settings fields from the model in django admin, but how do I get the form to include the select with the correct things in the select options for the user and then have it save the correct settings in the model on save?
I've read a bunch of other questions about custom django admin fields and got some ideas, but don't have a clear picture.