from _common.models import ActionButtons from _common.models import Table from django.db import models class UPPER_CASE(models.Model): nome = models.CharField(max_length=100) descricao = models.TextField(blank=True, null=True) criado_em = models.DateField(auto_now_add=True, auto_now=False) def __str__(self): return self.nome class UPPER_CASECrudList(): def get_data(self): data = {} data['icon'] = 'fas fa-tools' data['title'] = 'Lista de UPPER_CASE_PLURAL' data['btn_label'] = 'Novo UPPER_CASE' data['btn_link'] = 'LOWER_CASE_create' data['table'] = self.generate_table() return data def generate_table(self): table = {} LOWER_CASE_PLURAL = UPPER_CASE.objects.all() table['rows'] = [] for LOWER_CASE in LOWER_CASE_PLURAL: buttons = [("edit", "/LOWER_CASE/update/" + str(LOWER_CASE.id)), ("delete", "/LOWER_CASE/delete/" + str(LOWER_CASE.id))] aux = {} aux['id'] = LOWER_CASE.id aux['nome'] = LOWER_CASE.nome aux['descricao'] = LOWER_CASE.descricao aux['action'] = ActionButtons.generate(buttons) table['rows'] += [aux] table['labels'] = ['Id', 'Nome', 'Descrição', ''] table['alignment'] = [1, 1, 1, 2] tbl = Table(table['labels'], table['rows'], table['alignment']) table['body'] = tbl.getHTML() return table