models.py
from django.db import models
from ckeditor.fields import RichTextField
#
from applications.departamento.models import Departamento
class Habilidades(models.Model):
hablidad = models.CharField('Habilidad', max_length=50)
class meta:
verbose_name = 'Habilidad'
verbose_name_plural = 'Habilidades Empleados'
def __str__(self):
return str(self.id) + '-' + self.hablidad
# Create your models here.
class Empleado(models.Model):
""" Modelo para tabla empleado """
JOB_CHOICES = (
('0', 'CONTADOR'),
('1', 'ADMINISTRADOR'),
('2', 'ECONOMISTA'),
('3', 'OTRO'),
)
first_name = models.CharField('Nombres', max_length=60)
last_name = models.CharField('apellidos', max_length=60)
full_name = models.CharField(
'Nombres completos',
max_length=120,
blank=True
)
job = models.CharField('Teabajo', max_length=1, choices=JOB_CHOICES)
departamento = models.ForeignKey(Departamento, on_delete=models.CASCADE)
avatar = models.ImageField(upload_to='empleado', blank=True, null=True)
habilidades = models.ManyToManyField(Habilidades)
hoja_vida=RichTextField()
class Meta:
verbose_name = 'Mi Empleado'
verbose_name_plural = 'Empleados de la empresa'
ordering = ['-first_name', 'last_name']
unique_together = ('first_name', 'departamento')
def __str__(self):
return str(self.id) + '-' + self.first_name + '-' + self.last_name
views.py
class ListByAreaEmpleado(ListView):
""" lista empleados de un area """
template_name = 'persona/list_by_area.html'
context_object_name = 'empleados'
def get_queryset(self):
# el codigo que yo queira
area = self.kwargs['shorname']
lista = Empleado.objects.filter(
departamento__shor_name=area
)
return lista
urls.py
path(
'lista-by-area/<shorname>/',
views.ListByAreaEmpleado.as_view(),
name='emplados_area'
),
teplates/persona/list_by_area.html
{% extends 'base.html' %}
{% block title %}
lista empelados por departamento
{% endblock title %}
{% block content %}
{% include "includes/header.html" %}
<div class="grid-container">
<div class="grid-x">
<div class="cell">Empelados por area:</div>
<div class="cell">
<table>
<thead>
<tr>
<th width="200">ID</th>
<th>NOMBRES</th>
<th width="150">APELLIDOS</th>
<th width="150">DEPARTAMENTO</th>
<th width="150">ACCION</th>
</tr>
</thead>
<tbody>
{% for e in empleados %}
<tr>
<td>{{ e.id }}</td>
<td>{{ e.first_name }}</td>
<td>{{ e.last_name }}</td>
<td>{{ e.departamento }}</td>
<td><a class="button warning" href="{% url 'persona_app:empleado_detail' e.id %}">Ver</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock content %}
<h1>Lista empelados por departamento</h1>
<ul>
{% for e in object_list %}
<li>{{ e }}</li>
{% endfor %}
</ul>
Última modificación: 03 Jan 2023 19:19
No hay comentarios aún
Sé el primero en comentar este artículo