I have a model, which has an author ForeignKey
, as such:
class Appointment(models.Model):
# ...
author = models.ForeignKey(User)
I want the author
field to be set automatically when creating appointment to currently logged-in user. In other words, the author field should not appear in my Form class:
class AppointmentCreateForm(ModelForm):
class Meta:
model = Appointment
exclude = ('author')
There are two problems:
- How to access the form in generic CreateView and set the
author
? - How to tell the form to save the excluded field along with the values read from user input?