What is the best way to set a default value for a foreign key field in a model? Suppose I have two models, Student and Exam with student having
Student
Exam
I'm looking for the solution in Django Admin, then I found this:
class YourAdmin(admin.ModelAdmin) def get_changeform_initial_data(self, request): return {'owner': request.user}
this also allows me to use the current user.
see django docs