[Fixed]-DJango Model form that display's user.profile.name info instead user.username

1👍

✅

You can override init method and save student profile str as member variable of the form:

class AttendanceForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(AttendanceForm, self).__init__(*args, **kwargs)
        self.student_string = self.instance.student.profile.__str__()

and then use it somewhere in the form:

<p>{{ form.student_string }}</p>

Leave a comment