# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User

class Account(models.Model):
    account_number = models.CharField(max_length=30)
    agency_number = models.CharField(max_length=30)
    created_at = models.DateTimeField(auto_now=True)
    status = models.BooleanField(default="")
    accountant = models.ForeignKey(
        User,
        on_delete=models.CASCADE
    )

    class Meta:
        unique_together = ('accountant','account_number','agency_number')


class Cards(models.Model):
    name = models.CharField(max_length=100, unique=True)
    description = models.CharField(max_length=100)
    flag = models.CharField(max_length=100)
    status = models.BooleanField(default=True)

    def save(self, *args, **kwargs):
        cards = Cards.objects.filter(name=self.name)
        if len(cards) == 0:
            super(Cards, self).save(*args, **kwargs)


    def __str__(self):
        return self.name

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = 'Card'
        verbose_name_plural = 'Cards'
