Skip to content

Instantly share code, notes, and snippets.

@alisonamerico
Created October 24, 2019 17:33
Show Gist options
  • Save alisonamerico/78bc25c9622de34ea9a7875adb74db63 to your computer and use it in GitHub Desktop.
Save alisonamerico/78bc25c9622de34ea9a7875adb74db63 to your computer and use it in GitHub Desktop.
from django.db import models
class Country(models.Model):
id = models.AutoField(db_column='ID_COUNTRY', primary_key=True)
name = models.CharField(db_column='NAME', max_length=30)
initials = models.CharField(db_column='INITIALS', max_length=4, blank=True, null=True)
class Meta:
managed = False
db_table = 'COUNTRY'
class State(models.Model):
id = models.AutoField(db_column='ID_STATE', primary_key=True)
country = models.ForeignKey(Country, on_delete=models.CASCADE, db_column='ID_COUNTRY')
name = models.CharField(db_column='NAME', max_length=100)
initials = models.CharField(db_column='INITIALS', max_length=4, blank=True, null=True)
def __str__(self):
"""A string representation of the model."""
return self.name
class Meta:
managed = False
db_table = 'STATE'
class VariableType(models.Model):
id = models.AutoField(db_column='ID_VARIABLE', primary_key=True)
name = models.CharField(db_column='NAME', max_length=30)
class Meta:
managed = False
db_table = 'VARIABLE_TYPE'
class Variable(models.Model):
id = models.AutoField(db_column='ID_VARIABLE', primary_key=True)
type = models.ForeignKey('VariableType', on_delete=models.CASCADE, db_column='TYPE_ID_VARIABLE')
name = models.CharField(db_column='NAME', max_length=40)
def __str__(self):
"""A string representation of the model."""
return self.name
class Meta:
managed = False
db_table = 'VARIABLE'
class Unity(models.Model):
id = models.AutoField(db_column='ID_UNITY', primary_key=True)
name = models.CharField(db_column='NAME', max_length=30)
description = models.CharField(db_column='DESCRIPTION', max_length=100)
def __str__(self):
"""A string representation of the model."""
return self.name
class Meta:
managed = False
db_table = 'UNITY_TABLE'
class GlobalVariable(models.Model):
id = models.AutoField(db_column='ID_GLOBAL_VARIABLE', primary_key=True, unique=True)
variable = models.ForeignKey('Variable', on_delete=models.CASCADE, db_column='ID_VARIABLE', null=True)
unity = models.ForeignKey('Unity', db_column='ID_UNITY', on_delete=models.CASCADE)
state = models.ForeignKey('State', related_name='global_variable', on_delete=models.CASCADE, db_column='ID_STATE', null=True, unique=True)
value = models.DecimalField(db_column='VALUE', max_digits=18, decimal_places=9, blank=True, null=True) # Field name made lowercase.
month = models.DecimalField(db_column='MONTH', max_digits=2, decimal_places=0, blank=True, null=True) # Field name made lowercase.
year = models.DecimalField(db_column='YEAR', max_digits=4, decimal_places=0, blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'GLOBAL_VARIABLE'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment