import uuid from django.db import models from django.contrib.auth.validators import UnicodeUsernameValidator from django.utils.translation import gettext_lazy as _ from django.conf import settings def generate_org_slug(): return uuid.uuid4().hex class Organization(models.Model): slug = models.CharField( max_length=64, unique=True, default=generate_org_slug) name = models.CharField( max_length=150, unique=True, validators=(UnicodeUsernameValidator(),), help_text='Required. 150 characters or fewer.' 'Letters, digits and @/./+/-/_ only.', error_messages={ 'unique': _('An organization with that name already exists.'), }, ) logo = models.URLField( default='https://img2.pingcap.com/forms/d/d/ddfb57e828afbc459fece3848da3ef5bd5911683.png') introduction = models.CharField(max_length=255, blank=True, null=True) company_name = models.CharField(max_length=150, blank=True, null=True) industry_type_code = models.CharField(max_length=64, blank=True, null=True) industry_type_text = models.CharField(max_length=64, blank=True, null=True) member_range_code = models.CharField(max_length=64, blank=True, null=True) member_range_text = models.CharField(max_length=64, blank=True, null=True) job_title_code = models.CharField(max_length=64, blank=True, null=True) job_title_text = models.CharField(max_length=64, blank=True, null=True) company_base_code = models.CharField(max_length=64, blank=True, null=True) company_base_text = models.CharField(max_length=64, blank=True, null=True) incumbency_cert = models.ForeignKey( 'pingcap_sso.Upload', blank=True, null=True, on_delete=models.DO_NOTHING ) contact_phone = models.CharField( max_length=32, null=True, blank=True, help_text='Phone number is required.', error_messages={ 'unique': 'A user with that phone number already exists' } ) contact_email = models.EmailField(null=True, blank=True) topic_daily_urgency_times = models.IntegerField(default=1) user_count = models.IntegerField(default=0) topic_urgency_count = models.IntegerField(default=0) created_by_user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: db_table = 'pingcap_organization' permissions = ( ('manage_org_system', 'Manage organization'), ) def __str__(self): return self.name