expephalon/core/models/profiles.py

49 lines
1.8 KiB
Python
Raw Normal View History

from polymorphic.models import PolymorphicModel
from phonenumber_field.modelfields import PhoneNumberField
from internationalflavor.vat_number.models import VATNumberField
from django_countries.fields import CountryField
from django.db.models import OneToOneField, CASCADE, ImageField, Model, ForeignKey, SET_DEFAULT, ManyToManyField, DateTimeField, TextField
from django.contrib.auth import get_user_model
from core.helpers.files import generate_storage_filename
from core.models.local import Currency
from core.models.brands import Brand
from core.fields.base import LongCharField
class ClientGroup(Model):
name = LongCharField()
class Profile(PolymorphicModel):
user = OneToOneField(get_user_model(), CASCADE)
mobile = PhoneNumberField(blank=True)
class AdminProfile(Profile):
role = LongCharField()
image = ImageField(null=True, blank=True, upload_to=generate_storage_filename)
display_name = LongCharField("Internal Display Name", null=True, blank=True)
@property
def get_internal_name(self):
return self.display_name if self.display_name else self.user.get_full_name
class ClientProfile(Profile):
company = LongCharField()
address1 = LongCharField()
address2 = LongCharField()
zip = LongCharField()
city = LongCharField()
state = LongCharField()
country = CountryField()
vat_id = VATNumberField()
company_id = LongCharField()
default_currency = ForeignKey(Currency, on_delete=SET_DEFAULT, default=Currency.get_base)
client_groups = ManyToManyField(ClientGroup)
brands = ManyToManyField(Brand)
marketing_opt_in = DateTimeField(null=True)
pgp_key = TextField(null=True)
main_client = ForeignKey("self", null=True, on_delete=SET_DEFAULT, default=None)
@property
def get_nda(self):
return None