Models
Here are some of the Cubed models used in our system.
DeactivateBase¶
An inheritable class that overwrites the standard delete functionality that comes as part of the Django Models. The overwritten delete function will no longer delete a row of data but instead set it's active column to false.
Location
utils.model_helpers
Example:
class Pattern(DeactivateBase):
referer = models.ForeignKey(Referer, related_name='patterns', on_delete=models.PROTECT)
pattern = models.CharField(max_length=200)
active = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True, db_index=True)
updated = models.DateTimeField(auto_now=True, db_index=True)
class Meta(UnManaged):
db_table = 'attrib_pattern'
def __unicode__(self):
return self.pattern
pattern = Pattern.objects.get(id=1)
pattern.delete()
The row in the database will not be deleted, and instead it's "active" column will be set to 0/False.
DeletedBase¶
An inheritable class that overwrites the standard delete functionality that comes as part of the Django Models. The overwritten delete function will no longer delete a row of data but instead set it's deleted column to true, and its active column to false.
Location
utils.model_helpers
Example:
class APIAdwordsConnection(DeletedBase):
access_token = models.CharField(max_length=2000)
refresh_token = models.CharField(max_length=2000)
scope = models.CharField(max_length=2000)
created = models.DateTimeField(auto_now_add=True, db_index=True)
updated = models.DateTimeField(auto_now=True, db_index=True)
name = models.CharField(max_length=2000)
adwords_id = models.CharField(max_length=50)
cubed_user_id = models.IntegerField()
active = models.BooleanField(default=True)
deleted = models.BooleanField(default=False)
When the below code is run:
ad_con = APIAdwordsConnection.objects.get(id=1)
ad_con.delete()
The row in the database will not be deleted, however it's "deleted" will be set to 1/True, and it's "active" column will be set to 0/False.