Skip to content

Instantly share code, notes, and snippets.

@fandrefh
Created April 17, 2020 23:42
Show Gist options
  • Save fandrefh/6bec5bd36ce7b28536d437810712b096 to your computer and use it in GitHub Desktop.
Save fandrefh/6bec5bd36ce7b28536d437810712b096 to your computer and use it in GitHub Desktop.
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)
customer = GenericRelation(Customer)
class Meta:
verbose_name = 'Pessoa Física'
verbose_name_plural = 'Pessoas Físicas'
def __str__(self):
return self.name
class LegalPerson(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField('Nome', max_length=200)
registered_number = models.CharField('CNPJ', max_length=18, unique=True, default='', blank=True)
customer = GenericRelation(Customer)
class Meta:
verbose_name = 'Pessoa Jurídica'
verbose_name_plural = 'Pessoas Jurídicas'
def __str__(self):
return self.name
class Order(models.Model):
cost = models.DecimalField(max_digits=19, decimal_places=2)
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
class Meta:
verbose_name = 'Pedido'
verbose_name_plural = 'Pedidos'
def __str__(self):
return self.customer.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment