Create LongCharField to make code prettier

Create Models for clients and dummy model for brands
This commit is contained in:
Kumi 2020-05-27 15:06:38 +02:00
parent d6e753e264
commit 1efda993fd
9 changed files with 60 additions and 13 deletions

0
core/fields/__init__.py Normal file
View file

6
core/fields/base.py Normal file
View file

@ -0,0 +1,6 @@
from django.db.models import CharField
class LongCharField(CharField):
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 255
super().__init__(*args, **kwargs)

4
core/models/brands.py Normal file
View file

@ -0,0 +1,4 @@
from django.db.models import Model
class Brand(Model):
pass

View file

@ -1,6 +1,8 @@
from django.db.models import Model, CharField, DateTimeField, BooleanField
from django.db.models import Model, DateTimeField, BooleanField
from core.fields.base import LongCharField
class CronLog(Model):
task = CharField(max_length=255)
task = LongCharField()
execution = DateTimeField(auto_now_add=True)
locked = BooleanField(default=True)

View file

@ -1,15 +1,16 @@
from django.db.models import Model, CharField, ImageField, FileField, ManyToManyField, ForeignKey, BooleanField, CASCADE
from django.db.models import Model, ImageField, FileField, ManyToManyField, ForeignKey, BooleanField, CASCADE
from django.contrib.auth import get_user_model
from polymorphic.models import PolymorphicModel
from core.helpers.files import generate_storage_filename
from core.models.profiles import Profile
from core.fields.base import LongCharField
# Create your models here.
class BaseFile(PolymorphicModel):
filename = CharField(max_length=255)
filename = LongCharField()
class ImageFile(BaseFile):
rawfile = ImageField(upload_to=generate_storage_filename)

View file

@ -2,8 +2,10 @@ from django.db.models import Model, CharField, BooleanField, DecimalField, Forei
from django_countries.fields import CountryField
from core.fields.base import LongCharField
class Currency(Model):
name = CharField(max_length=255, unique=True)
name = LongCharField(unique=True)
code = CharField(max_length=16, unique=True)
symbol = CharField(max_length=8)
base = BooleanField(default=False)
@ -18,7 +20,7 @@ class Currency(Model):
return cls.objects.get(base=True)
class TaxPolicy(Model):
name = CharField(max_length=255, blank=True)
name = LongCharField(blank=True)
default_rate = DecimalField(default=0, max_digits=10, decimal_places=5)
def get_applicable_rate(self, country, reverse_charge=False):

View file

@ -1,4 +1,5 @@
from core.models.billable import CycleChoices
from core.fields.base import LongCharField
from django.db.models import Model, IntegerChoices, PositiveIntegerField, DecimalField, ForeignKey, CASCADE, CharField, TextField, ManyToManyField
@ -9,12 +10,12 @@ import logging
logger = logging.getLogger(__name__)
class ProductGroup(Model):
name = CharField(max_length=255)
name = LongCharField()
class Product(Model):
name = CharField(max_length=255)
name = LongCharField()
description = TextField(null=True, blank=True)
handler_module = CharField(max_length=255, null=True, blank=True)
handler_module = LongCharField(null=True, blank=True)
product_groups = ManyToManyField(ProductGroup)
@property

View file

@ -1,20 +1,49 @@
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, CharField, ImageField
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 = CharField(max_length=255)
role = LongCharField()
image = ImageField(null=True, blank=True, upload_to=generate_storage_filename)
display_name = CharField("Internal Display Name", max_length=255, null=True, blank=True)
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
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

View file

@ -15,3 +15,5 @@ python-memcached
django-countries
pyuca
git+https://kumig.it/kumisystems/parse_crontab.git
django-internationalflavor
suds-jurko