What I want to do is, be able to use the first name of the user that is registered in the database using the User model that django has by default, my idea is to use its name as a sort of selector with a foreign key, so that when I save my document I refer to that user that I select, here is my model code
models.py
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
class analisis_doc(models.Model):
nombre_doc = models.CharField(max_length=40)
referencia=models.CharField(max_length=200)
area = models.CharField(max_length=30)
user = models.ForeignKey(User, default=1)
forms.py
from django import forms
from .models import analisis_doc
class analisis_form(forms.ModelForm):
class Meta:
model=cargo
fields=[
'nombre_doc',
'referencia',
'area',
'user',
]
labels={
'nombre_doc':('Nombre del documento'),
'referencia':('Referencias'),
'area':('Area'),
'user':('Seleccione nomrbre del usuario'),
}
widgets={
'nombre_doc':forms.TextInput(attrs={'class':'form=control'}),
'referencia':forms.TextInput(attrs={'class':'form=control'}),
'area':forms.TextInput(attrs={'class':'form=control'}),
'user':forms.Select(attrs={'class':'form=control'}),
}
This is my die that I have of how I could use the name of the table User has django but I think it's wrong, if someone could, please tell me where I'm wrong or how should I do it?