-1
I am doing a project using Django 3.1.2, this project needs a log.
I created a template for logs:
class Log(models.Model):
Usuario = models.CharField('Usuário que fez a ação', max_length=100)
Perfil = models.SmallIntegerField('Quem está sofrendo a ação', choices=PERFIL_CHOICE)
Acao = models.CharField('Tipo de Ação Realizada', max_length=2, choices=ACAO_CHOICE)
Resultado = models.JSONField('Resultado', null=True, blank=True)
Processando = models.BooleanField('Processando', default=True)
TituloProcesso = models.CharField("Titulo do Processo", max_length=100, null=True, blank=True)
DataAcao = models.DateTimeField('Data da Ação', auto_now_add=True)
The model log has the "Result" field which is of type Jsonfield, this field is working correctly.
The data that is saved in the field is dynamic, so the json keys and values will not always be the same, so it is necessary easier to display this field in the model.
I was looking for "Django-jsonfiel", it doesn’t work in Django 3.1
Does anyone know any way to display this already dynamically formatted field?
What do you call showing off? Something like
print(json.dumps(SEU_JSON, indent=4, sort_keys=True))
helping?– Paulo Marques
Good afternoon, this would be a solution yes only that I tried to play in the template, putting this formatting in a variable so that in the template does not look the same in the terminal print, does not take the formatting.
– Romulo Ferreira Mesquita
Tries to pass the
json.dumps(SEU_JSON, indent=4)
to the template and show there with{{ VARIAVEL_JSON | linebreaks }}
– Paulo Marques
Oops good morning, thanks a lot @Paulomarques worked, I was wondering if there are any tags for the identations and if you have any link with these tags so I can give a studied in them .
– Romulo Ferreira Mesquita
View the Django documentation here
– Paulo Marques