SHARE
TWEET

models

a guest Aug 14th, 2019 276 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.db import models
  2.  
  3. # Create your models here.
  4. # This is an auto-generated Django model module.
  5. # You'll have to do the following manually to clean this up:
  6. #   * Rearrange models' order
  7. #   * Make sure each model has one field with primary_key=True
  8. #   * Make sure each ForeignKey has `on_delete` set to the desired behavior.
  9. #   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
  10. # Feel free to rename the models, but don't rename db_table values or field names.
  11. from django.db import models
  12. from django.contrib.postgres.fields import ArrayField
  13. from django.contrib.auth.models import User as AuthUser
  14. from rest_framework.authtoken.models import Token
  15. from django.db.models.signals import post_save
  16. from django.dispatch import receiver
  17. from django.conf import settings
  18.  
  19.  
  20. class UserAuthUser(models.Model):
  21.     user = models.ForeignKey('User', models.DO_NOTHING, blank=True, null=True)
  22.     auth_user = models.ForeignKey(AuthUser, models.DO_NOTHING, blank=True, null=True)
  23.  
  24.     class Meta:
  25.         managed = False
  26.         db_table = 'user_authuser'
  27.  
  28.  
  29. class UserAdditionalData(models.Model):
  30.     user = models.ForeignKey(AuthUser, models.CASCADE, blank=False, null=False)
  31.     default_branch = models.ForeignKey('Branches', models.DO_NOTHING, blank=True, null=True)
  32.     is_admin = models.BooleanField(blank=False,null=False,default=False)
  33.     phone = models.CharField(blank=True, null=True, max_length=12)
  34.  
  35.     class Meta:
  36.         managed = True
  37.         db_table = 'user_additionaldata'
  38.         verbose_name_plural = "user additional data"
  39.  
  40.     def __str__(self):
  41.         return self.user.first_name + ' ' + self.user.last_name + ' (' + self.user.username + ')'
  42.  
  43.  
  44. class CompanyUser(models.Model):
  45.     user = models.ForeignKey(AuthUser, models.CASCADE, blank=False, null=True)
  46.     company = models.ForeignKey('Companies', models.DO_NOTHING, blank=False, null=True)
  47.  
  48.     class Meta:
  49.         managed = True
  50.         db_table = 'user_companyuser'
  51.  
  52.     def __str__(self):
  53.         return self.user.username
  54.  
  55.  
  56. class Branches(models.Model):
  57.     name = models.CharField(max_length=50)
  58.     description = models.CharField(max_length=255)
  59.     created_at = models.DateTimeField()
  60.     filter_date_min = models.DateField()
  61.     filter_date_max = models.DateField()
  62.  
  63.     class Meta:
  64.         managed = True
  65.         db_table = 'branches'
  66.         verbose_name_plural = "branches"
  67.  
  68.     def __str__(self):
  69.         return self.name
  70.  
  71.  
  72. class Companies(models.Model):
  73.     name = models.CharField(max_length=50)
  74.     created_at = models.DateTimeField()
  75.     tax_number = models.CharField(max_length=50, blank=True, null=True)
  76.     region = models.ForeignKey('RegionsRegion', models.DO_NOTHING, blank=True, null=True)
  77.     braintree_id = models.CharField(max_length=12, null=True, blank=True)
  78.  
  79.     class Meta:
  80.         managed = True
  81.         db_table = 'companies'
  82.         verbose_name_plural = "companies"
  83.  
  84.  
  85. class PaymentMethod(models.Model):
  86.     braintree_cc_id = models.CharField(max_length=20, null=True, blank=True)
  87.     masked_number = models.CharField(max_length=20, null=True, blank=True)
  88.     expiration_year = models.CharField(max_length=20, null=True, blank=True)
  89.     expiration_month = models.CharField(max_length=20, null=True, blank=True)
  90.     validation_code = models.CharField(max_length=4, null=True, blank=True)
  91.     active = models.BooleanField()
  92.     company = models.ForeignKey('Companies', models.DO_NOTHING, blank=True, null=True)
  93.  
  94.  
  95. class Import(models.Model):
  96.     user = models.ForeignKey(AuthUser, models.DO_NOTHING, blank=True, null=True)
  97.     status = models.CharField(max_length=255, blank=True, null=True)
  98.     error = models.CharField(max_length=255, blank=True, null=True)
  99.     started_at = models.DateTimeField()
  100.     finished_at = models.DateTimeField(blank=True, null=True)
  101.     company = models.ForeignKey('Companies', models.DO_NOTHING, blank=True, null=True)
  102.     uploaded_file = models.FileField(blank=True, null=True, upload_to='import_files/')
  103.  
  104.     class Meta:
  105.         managed = True
  106.         db_table = 'import'
  107.  
  108.     def __int__(self):
  109.         return self.id
  110.  
  111.  
  112. class ImportFiles(models.Model):
  113.     name = models.CharField(max_length=50)
  114.     created_at = models.DateTimeField()
  115.     path = models.CharField(max_length=255, blank=True, null=True)
  116.     fk_import = models.ForeignKey('Import', models.DO_NOTHING, blank=True, null=True)
  117.     values = ArrayField(ArrayField(models.TextField()), blank=True, null=True)
  118.  
  119.     class Meta:
  120.         managed = True
  121.         db_table = 'import_files'
  122.         verbose_name_plural = "import files"
  123.  
  124.     def __str__(self):
  125.         return self.name
  126.  
  127.  
  128. class Integrations(models.Model):
  129.     company = models.ForeignKey(Companies, models.DO_NOTHING, blank=True, null=True)
  130.     kpi = models.ForeignKey('Kpi', models.DO_NOTHING, blank=True, null=True)
  131.     created_at = models.DateTimeField()
  132.     status = models.CharField(max_length=50)
  133.     subdomain = models.CharField(max_length=50, blank=True, null=True)
  134.     token = models.CharField(max_length=50, blank=True, null=True)
  135.     login = models.CharField(max_length=50, blank=True, null=True)
  136.     password = models.CharField(max_length=50, blank=True, null=True)
  137.  
  138.     class Meta:
  139.         managed = True
  140.         db_table = 'integrations'
  141.         verbose_name_plural = "integrations"
  142.  
  143.     def __str__(self):
  144.         return self.pk
  145.  
  146.  
  147. class Kpi(models.Model):
  148.     branch = models.ForeignKey(Branches, models.DO_NOTHING, blank=True, null=True)
  149.     name = models.CharField(max_length=50)
  150.     benchmark_value = models.IntegerField()
  151.     kpi_order = models.IntegerField()
  152.     dashboard_order = models.IntegerField()
  153.     unit = models.CharField(max_length=255)
  154.     is_asc_positive = models.IntegerField()
  155.     created_at = models.DateTimeField(blank=True, null=True)
  156.     colour = models.CharField(max_length=255)
  157.  
  158.     class Meta:
  159.         managed = True
  160.         db_table = 'kpi'
  161.  
  162.     def __str__(self):
  163.         return self.name
  164.  
  165.  
  166. class KpiIntegrations(models.Model):
  167.     kpi = models.ForeignKey(Kpi, models.DO_NOTHING, blank=True, null=True)
  168.     active = models.IntegerField()
  169.     created_at = models.DateTimeField(blank=True, null=True)
  170.     name = models.CharField(max_length=255)
  171.  
  172.     class Meta:
  173.         managed = True
  174.         db_table = 'kpi_integrations'
  175.         verbose_name_plural = "kpi integrations"
  176.  
  177.     def __str__(self):
  178.         return self.name
  179.  
  180.  
  181. class KpiValues(models.Model):
  182.     kpi = models.ForeignKey(Kpi, models.DO_NOTHING, blank=True, null=True)
  183.     branch = models.ForeignKey(Branches, models.DO_NOTHING, blank=True, null=True)
  184.     company = models.ForeignKey(Companies, models.DO_NOTHING, blank=True, null=True)
  185.     kpi_value = models.FloatField(blank=False, null=False)
  186.     datetime = models.DateTimeField(blank=False, null=False)
  187.     created_at = models.DateTimeField(blank=False, null=False)
  188.     from_import = models.ForeignKey('Import', models.DO_NOTHING, blank=True, null=True)
  189.  
  190.     class Meta:
  191.         managed = True
  192.         db_table = 'kpi_values'
  193.         verbose_name_plural = "kpi values"
  194.  
  195.     def __int__(self):
  196.         return self.pk
  197.  
  198.  
  199. class LoginDates(models.Model):
  200.     user = models.ForeignKey('User', models.DO_NOTHING, blank=True, null=True)
  201.     logged_in_at = models.DateTimeField()
  202.  
  203.     class Meta:
  204.         managed = True
  205.         db_table = 'login_dates'
  206.         verbose_name_plural = "login dates"
  207.  
  208.  
  209. class MigrationVersions(models.Model):
  210.     version = models.CharField(primary_key=True, max_length=255)
  211.  
  212.     class Meta:
  213.         managed = True
  214.         db_table = 'migration_versions'
  215.  
  216.  
  217. class PasswordToken(models.Model):
  218.     user = models.ForeignKey(AuthUser, models.DO_NOTHING)
  219.     token = models.CharField(unique=True, max_length=255)
  220.     expires_at = models.DateTimeField()
  221.     active = models.BooleanField(default=False, blank=False, null=False)
  222.  
  223.     class Meta:
  224.         managed = True
  225.         db_table = 'password_token'
  226.  
  227.     def __str__(self):
  228.         return self.user.username
  229.  
  230.  
  231. class RegionsRegion(models.Model):
  232.     created_at = models.DateTimeField()
  233.     street = models.CharField(max_length=255)
  234.     number = models.CharField(max_length=50)
  235.     zip_code = models.CharField(max_length=50)
  236.     city = models.CharField(max_length=255)
  237.  
  238.     class Meta:
  239.         managed = True
  240.         db_table = 'regions_region'
  241.  
  242.     def __int__(self):
  243.         return self.id
  244.  
  245.  
  246. class User(models.Model):
  247.     def_branch = models.ForeignKey(Branches, models.DO_NOTHING, blank=True, null=True)
  248.     company = models.ForeignKey(Companies, models.DO_NOTHING, blank=True, null=True)
  249.     email = models.CharField(unique=True, max_length=255)
  250.     username = models.CharField(max_length=40, blank=True, null=True)
  251.     firstname = models.CharField(max_length=40)
  252.     lastname = models.CharField(max_length=40)
  253.     role = models.CharField(max_length=50)
  254.     phone_number = models.CharField(max_length=50, blank=True, null=True)
  255.     is_admin = models.IntegerField()
  256.     chartmarine_user = models.IntegerField()
  257.     password = models.CharField(max_length=64)
  258.     active = models.IntegerField()
  259.     verification_hash = models.CharField(max_length=255)
  260.     verified_at = models.DateTimeField(blank=True, null=True)
  261.  
  262.     class Meta:
  263.         managed = True
  264.         db_table = 'user'
  265.  
  266.     def __str__(self):
  267.         return self.username
  268.  
  269.  
  270. class UserOnboarding(models.Model):
  271.     user = models.ForeignKey(User, models.DO_NOTHING, blank=True, null=True)
  272.     last_onboarding_step = models.IntegerField()
  273.     onboarded = models.IntegerField()
  274.     terminated_onboarding = models.IntegerField()
  275.  
  276.     class Meta:
  277.         managed = True
  278.         db_table = 'user_onboarding'
  279.  
  280.  
  281. class VerificationHash(models.Model):
  282.     user = models.ForeignKey(AuthUser, models.CASCADE, blank=False, null=False)
  283.     verification_hash = models.CharField(blank=False, null=False, max_length=255)
  284.     active = models.BooleanField(null=False, blank=False)
  285.     created_at = models.DateTimeField(blank=False, null=False)
  286.  
  287.     def __str__(self):
  288.         return self.user.username
  289.  
  290.  
  291. class CustomDataModel(models.Model):
  292.     datetime = models.DateTimeField(blank=False, null=False)
  293.     created_at = models.DateTimeField(blank=False, null=False)
  294.     value = models.DecimalField(blank=True, null=True, max_digits=10, decimal_places=2)
  295.     datapoint_name = models.CharField(blank=True, null=True, max_length=255)
  296.     company = models.ForeignKey(Companies, models.DO_NOTHING, blank=True, null=True)
  297.     category = models.CharField(blank=True, null=True, max_length=255)
  298.     custom_str_1 = models.CharField(blank=True, null=True, max_length=255)
  299.     custom_str_2 = models.CharField(blank=True, null=True, max_length=255)
  300.     additional_value = models.DecimalField(blank=True, null=True, max_digits=10, decimal_places=2)
  301.     custom_category_1 = models.CharField(blank=True, null=True, max_length=255)
  302.     custom_category_2 = models.CharField(blank=True, null=True, max_length=255)
  303.     kpi = models.ForeignKey(Kpi, models.DO_NOTHING, blank=True, null=True)
  304.     branch = models.ForeignKey(Branches, models.DO_NOTHING, blank=True, null=True)
  305.     from_import = models.ForeignKey('Import', models.DO_NOTHING, blank=True, null=True)
  306.  
  307.     def __str__(self):
  308.         return self.datapoint_name
  309.  
  310.     def datetime_day(self):
  311.         return self.datetime.strftime('%d')
  312.  
  313.  
  314. class KpiValuesCalculated(models.Model):
  315.     created_at = models.DateTimeField(blank=False, null=False)
  316.     branch = models.ForeignKey(Branches, models.DO_NOTHING, blank=True, null=True)
  317.     nominator = models.ForeignKey(Kpi, models.DO_NOTHING, blank=True, null=True, related_name='nominator')
  318.     denominator = models.ForeignKey(Kpi, models.DO_NOTHING, blank=True, null=True, related_name='denominator')
  319.     kpi = models.ForeignKey(Kpi, models.DO_NOTHING, blank=True, null=True)
  320.  
  321.  
  322. class CustomDashboardModel(models.Model):
  323.     created_at = models.DateTimeField(blank=False, null=False)
  324.     company = models.ForeignKey('Companies', models.DO_NOTHING, blank=False, null=False)
  325.     external_id = models.CharField(blank=False, null=False, max_length=255)
  326.     name = models.CharField(blank=True, null=True, max_length=255)
  327.     is_active = models.BooleanField(blank=False, null=False, default=True)
  328.  
  329.     def __str__(self):
  330.         return self.external_id
  331.  
  332.  
  333. class CustomGraphModel(models.Model):
  334.     parent_id = models.CharField(blank=False, null=False, max_length=20)
  335.     graph_id = models.CharField(blank=False, null=False, max_length=20)
  336.     dashboard = models.ForeignKey('CustomDashboardModel', models.DO_NOTHING, blank=False, null=False)
  337.     graph_width = models.DecimalField(blank=False, null=False, max_digits=4, decimal_places=2)
  338.     graph_height = models.DecimalField(blank=False, null=False, max_digits=4, decimal_places=2)
  339.     graph_position_x = models.DecimalField(blank=False, null=False, max_digits=4, decimal_places=2)
  340.     graph_position_y = models.DecimalField(blank=False, null=False, max_digits=4, decimal_places=2)
  341.     graph_type = models.CharField(blank=False, null=False, max_length=15)
  342.     aggregation = models.CharField(blank=False, null=False, max_length=15)
  343.     value = models.CharField(blank=False, null=False, max_length=15)
  344.     filter_by = models.CharField(blank=True, null=True, max_length=15)
  345.     filter_min = models.CharField(blank=True, null=True, max_length=15)
  346.     filter_max = models.CharField(blank=True, null=True, max_length=15)
  347.     agr_data_selected = models.CharField(blank=True, null=True, max_length=15)
  348.     is_active = models.BooleanField(blank=False, null=False, default=True)
  349.  
  350.     def __str__(self):
  351.         return self.graph_id
  352.  
  353.  
  354. class CustomCohortReport(models.Model):
  355.     company = models.ForeignKey('Companies', models.DO_NOTHING, blank=False, null=False)
  356.     external_id = models.CharField(blank=False, null=False, max_length=255)
  357.     name = models.CharField(blank=True, null=True, max_length=255)
  358.     created_at = models.DateTimeField(blank=False, null=False)
  359.     updated_at = models.DateTimeField(blank=False, null=False)
  360.     datapoint_name = models.CharField(blank=False, null=False, max_length=15)
  361.     value = models.CharField(blank=False, null=False, max_length=15)
  362.     sort = models.CharField(blank=False, null=False, max_length=15)
  363.     is_active = models.BooleanField(blank=False, null=False, default=True)
  364.  
  365.     def __str__(self):
  366.         return self.company.name + ' ' + self.name
  367.  
  368.  
  369. class LandingPageSections(models.Model):
  370.     section_header = models.CharField(blank=False, null=False, max_length=122)
  371.     section_body = models.TextField(blank=False, null=False, max_length=1500)
  372.     section_image = models.CharField(blank=True, null=True, max_length=122)
  373.  
  374.     def __str__(self):
  375.         return self.section_header
  376.  
  377.     class Meta:
  378.         verbose_name_plural = "landing page sections"
  379.  
  380.  
  381. class FeatureDescriptions(models.Model):
  382.     feature_name = models.CharField(blank=False, null=False, max_length=122)
  383.     feature_description = models.TextField(blank=False, null=False, max_length=1500)
  384.     feature_image_path = models.CharField(blank=False, null=False, max_length=122)
  385.  
  386.     def __str__(self):
  387.         return self.feature_name
  388.  
  389.     class Meta:
  390.         verbose_name_plural = "landing page features"
  391.  
  392.  
  393. class UserInvitationHash(models.Model):
  394.     company = models.ForeignKey('Companies', models.CASCADE, blank=False, null=False)
  395.     hash = models.CharField(max_length=255)
  396.     active = models.BooleanField(default=False, null=False, blank=False)
  397.     created_at = models.DateTimeField(null=False, blank=False)
  398.     email = models.CharField(max_length=50, blank=False, null=False)
  399.     def_branch = models.ForeignKey(Branches, models.DO_NOTHING, blank=True, null=True)
  400.     parent_id = models.IntegerField(blank=True, null=True)
  401.  
  402.  
  403. class OverviewNotification(models.Model):
  404.     company = models.ForeignKey(Companies, models.CASCADE, blank=False, null=False)
  405.     type = models.CharField(max_length=100)
  406.     active = models.BooleanField(default=True, null=False, blank=False)
  407.     headline = models.TextField(blank=True, null=True, max_length=255)
  408.     main_content = models.TextField(blank=False, null=False, max_length=1500)
  409.     created_at = models.DateTimeField(null=False, blank=False)
  410.     seen_at = models.DateTimeField(null=True, blank=True)
  411.     kpi = models.ForeignKey('Kpi', models.DO_NOTHING, blank=True, null=True)
  412.  
  413.  
  414. @receiver(post_save, sender=settings.AUTH_USER_MODEL)
  415. def create_auth_token(sender, instance=None, created=False, **kwargs):
  416.     if created:
  417.         Token.objects.create(user=instance)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top