I have two classes(tables) schools and students that are related together(foreignkey) When I create a new student I want it to autofill the school field (which is a foreignk
If you want to give a default value for your FK field go with default attribute. Django already gives the option to add a default value to your field.
DEFAULT_SCHOOL_ID = 1
class Student(models.Model):
...
school=models.ForeignKey(School, default=DEFAULT_SCHOOL_ID)
You are an overriding get_initial method its used for Returns the initial data to use for forms on this view not actually adding a default value to your field