Created
July 16, 2021 00:37
-
-
Save Marlysson/87d9f06a6109b4518368e8ced0fc8e1a to your computer and use it in GitHub Desktop.
Renderizando erro na view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if messages %} | |
<ul class="messages"> | |
{% for message in messages %} | |
<li {% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> | |
{% endfor %} | |
</ul> | |
{% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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