Hello,
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
self.request.user.cod_departamento_id
let it be something like that
self.request.department_table_name.department_name_field
That doesn’t work for me.
I want to do a get of the department that has the authenticated user
If the two tables are related, in the users table there is the field cod_departament that relates to the department table, where there is the full name.
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.