Skip to content

Instantly share code, notes, and snippets.

View fandrefh's full-sized avatar

Francisco André fandrefh

View GitHub Profile
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.
print('código com erro')
import psycopg2
class ConexaoDB:
def conectar(self):
conexao = psycopg2.connect(
host='localhost',
database='senacwebdb',
user='senacwebuser',
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;
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):
# 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.'),
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)
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)
import math
math.sqrt(9)
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.")