[Fixed]-Django form to display user attributes

1👍

Your UserGroupForm is a model-form, based on the UnitUser model.
The fields of the form are based on the fields of the model.

Since UnitUser doesn’t contain details about the user, but merely a single reference to the user model, the user model itself is only represented via a single field. The string representation of a user model is the username. I would think that’s the reason you see the username in your form.

In short: Your model-form considers the user just as a single field and will use the string representation of the value of that field as init-value.

If you want to display further attributes of the user in your form, you might have to construct a specific form for that purpose.

Leave a comment