I have these models:
class Direccion(models.Model):
pais = models.CharField(max_length=30)
estado = models.CharField(max_length=30)
municipio = models.CharField(max_length=30)
ciudad = models.CharField(max_length=40, null=True, blank=True)
calle = models.CharField(max_length=40)
colonia = models.CharField(max_length=30, null=True, blank=True)
numero_interior = models.IntegerField(null=True, blank=True)
numero_exterior = models.CharField(max_length=5, null=True, blank=True)
codigo_postal = models.IntegerField()
datos_adicionales = models.CharField(max_length=120, null=True, blank=True)
class Empleado(models.Model):
direccion = models.ForeignKey(Direccion, null=True, blank=True)
nombre = models.CharField(max_length=80)
apellido_paterno = models.CharField(max_length=80)
apellido_materno = models.CharField(max_length=80, blank=True, null=True)
rfc = models.CharField(max_length=18)
curp = models.CharField(max_length=18)
fecha_nacimiento = models.DateField(null=True, blank=True)
fecha_registro = models.DateTimeField(auto_now_add=True)
activo = models.IntegerField(default=1, editable=False)
And I call all the attributes of the model Empleado
of a table in my template, but inside a cell I want to call all the attributes of the address corresponding to each employee and concatenate them, I was looking for how to do it but not I find something close to what I want to do.
For now I'm just returning the values of the model Empleado
and the ID of the address like this:
class EmpleadosList(ListView):
model = Empleado
def get_queryset(self):
queryset = Empleado.objects.filter(activo=1).order_by('id')
return queryset
And in the template:
{% for empleado in object_list %}
<tr>
<td> {{ empleado.id }}</td>
<td> {{ empleado.nombre }} </td>
<td> {{ empleado.apellido_paterno }} </td>
<td> {{ empleado.apellido_materno }} </td>
<td> {{ empleado.fecha_nacimiento|date:"Y-m-d" }} </td>
<td> {{ empleado.curp }} </td>
<td> {{ empleado.rfc }} </td>
<td> {{ empleado.direccion_id }}</td>
</tr>
{% endfor %}