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
from django.db import models | |
from django.contrib.auth import get_user_model | |
from django.utils.translation import ugettext_lazy as _ | |
from baseapp.models import AbstractDateTimeBaseModel | |
from localflavor.br.br_states import STATE_CHOICES | |
# Create your models here. |
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
print('código com erro') |
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
import psycopg2 | |
class ConexaoDB: | |
def conectar(self): | |
conexao = psycopg2.connect( | |
host='localhost', | |
database='senacwebdb', | |
user='senacwebuser', |
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
select m.id as matricula, a.nome as aluno, c.nome as curso, m.data_matricula as data_matricula | |
from matricula as m left join aluno as a on m.aluno_id = a.id | |
left join curso as c on m.curso_id = c.id; |
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 BannerHome(models.Model): | |
title = models.CharField(verbose_name=_('Título do banner'), max_length=150) | |
description = models.TextField(verbose_name=_('Descrição'), null=True, blank=True, help_text=_('Opcional')) | |
image = models.ImageField(verbose_name=_('Banner'), upload_to='banners/home') | |
class Meta: | |
verbose_name = _('Banner Página Inicial') | |
verbose_name_plural = _('Banners Página Inicial') | |
def __str__(self): |
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
# models.py | |
class User(AbstractBaseUser, PermissionsMixin): | |
username_validator = UnicodeUsernameValidator() | |
id = models.UUIDField(verbose_name=_('ID'), primary_key=True, default=uuid.uuid4, editable=False) | |
username = models.CharField( | |
_('Usuário'), | |
max_length=150, | |
unique=True, | |
help_text=_('Obrigatório. 150 caracteres ou menos. Letras, números e os símbolos @/./+/-/_ são permitidos.'), |
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 Customer(models.Model): | |
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) | |
object_id = models.IntegerField() | |
content_object = GenericForeignKey() | |
class Individual(models.Model): | |
user = models.ForeignKey(User, on_delete=models.CASCADE) | |
name = models.CharField('Nome', max_length=200) | |
brazilian_cpf = models.CharField('CPF', max_length=14, unique=True, blank=True, null=True) |
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 user_login(request): | |
template_name = 'accounts/login.html' | |
if request.method == 'POST': | |
form = UserLogin(request.POST) | |
if form.is_valid(): | |
username = form.cleaned_data['username'] | |
password = form.cleaned_data['password'] | |
user = authenticate(request, username=username, password=password) | |
if user is not None: | |
login(request, user) |
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
import math | |
math.sqrt(9) |
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 clean(self): | |
model = self.__class__ | |
if model.objects.count() > 0 and self.id != model.objects.get().id: | |
raise ValidationError("Você já tem um perfil cadastrado.") |
NewerOlder