from django.contrib.auth import get_user_model
from django.db import models

from core.custom_fields import LowerCaseEmailField, CustomizedIBANField
from core.models import DatedModel

User = get_user_model()


class Debtor(DatedModel):
    """Debtor Model representation"""
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    email = LowerCaseEmailField(unique=True)
    iban = CustomizedIBANField(accept_nordea_extensions=True)
    created_by = models.ForeignKey(User, on_delete=models.PROTECT)

    def save(self, *args, **kwargs):
        """Invoke validations before save it"""
        self.full_clean()
        super().save(*args, **kwargs)

    def __str__(self):
        return self.email

from django.contrib.auth import get_user_model
from django.db import models

from core.custom_fields import LowerCaseEmailField, CustomizedIBANField
from core.models import DatedModel

User = get_user_model()


class Debtor(DatedModel):
    """Debtor Model representation"""
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=20)
    email = LowerCaseEmailField(unique=True)
    iban = CustomizedIBANField(accept_nordea_extensions=True)
    created_by = models.ForeignKey(User, on_delete=models.PROTECT)

    def save(self, *args, **kwargs):
        """Invoke validations before save it"""
        self.full_clean()
        super().save(*args, **kwargs)

    def __str__(self):
        return self.email

Debtor Model representation Invoke validations before save it