I have two queries that I think may be related.
I have a form where there are some fields that are entered by the user and others that are assigned directly by the app by default. These default fields also appear on the form through views.py with code:
The cod_departamento_id field is from the users table but I would like to take a field from another table, specifically a table called department that is also in the same database
The thing is like indicating instead of
let it be something like that
That doesn’t work for me.
If you have an instance of Usuario named user, then the related object of type departamento would be referenced as user.cod_departamento. (cod_departamento is the name of the ForeignKey referencing the departamento model.)
If you have an instance of departamento named un_departamento, then you would reference the nombre_departamento field as un_departamento.nombre_departamento.
Putting those two together means that given a Usuario named user, you would access that character field as user.cod_departamento.nombre_departamento.