Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Created Jul 16, 2021
Embed
What would you like to do?
Renderizando erro na view.
class ModelA(models.Model):
a = models.CharField()
b = models.CharField()
c = models.CharField()
def save(self, *args, **kwargs):
c = self.a + self.b
super().save(*args, **kwargs)
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li {% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
def test_view(request):
# Recuperando os dados da request
valor_A = request.POST['A']
valor_B = request.POST['B']
# Verificando se já existe
ja_existe = ModelA.objects.filter(a=valor_A, b=valor_B).exists()
# Colocando no messages
if ja_existe:
messages.warning(request, 'Já existe um dado com as infos cadastradas.')
return render(request, 'template.html', context={})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment