This repository has been archived on 2025-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
facturio/accounts/models.py

31 lines
951 B
Python
Raw Normal View History

2023-12-18 22:09:18 +01:00
from django.contrib.auth.models import AbstractUser
2023-12-19 13:49:34 +01:00
from django.db import models
from django.utils.translation import gettext_lazy as _
2023-12-18 21:00:37 +01:00
2024-02-03 21:54:05 +01:00
from subjects.models import Subject
2023-12-18 22:09:18 +01:00
class User(AbstractUser):
2024-02-03 22:07:20 +01:00
REQUIRED_FIELDS = ['email', 'first_name', 'last_name']
2023-12-19 13:49:34 +01:00
2024-02-03 22:07:20 +01:00
first_name = models.CharField(_('first name'), max_length=150)
last_name = models.CharField(_('last name'), max_length=150)
email = models.EmailField(_('email address'))
2023-12-19 13:49:34 +01:00
2024-08-16 22:12:49 +02:00
supplier = models.ForeignKey(
Subject, models.PROTECT, _('supplier'), blank=True, null=True,
)
customers = models.ManyToManyField(
Subject, blank=True, verbose_name=_('customers'),
)
2024-02-03 21:54:05 +01:00
2025-02-17 22:10:38 +01:00
class Meta:
verbose_name = _("user")
verbose_name_plural = _("users")
2024-08-16 22:12:49 +02:00
def _get_m2m_ids(self, field: str):
return list(getattr(self, field).values_list('id', flat=True))
def get_customers(self) -> list[int]:
return self._get_m2m_ids('customers')