Skip to content

Overview

Django

The Cubed backend is built with Django, an open-source Python framework. Primarily, we use Django's ORM capabilities to retrieve collected data from the database. This data is mapped using Django 'models', which represent the stored data.

Here is an example of a Django model, which represents a visit to a client's website:

class Visit(models.Model):
    visitor     = models.ForeignKey(Visitor, related_name='%(class)ss', on_delete=models.PROTECT)
    token       = models.CharField(max_length=32, unique=True)
    referrer    = models.CharField(max_length=2000)
    views       = models.IntegerField()
    first_visit = models.DateTimeField(db_index=True)
    last_visit  = models.DateTimeField(db_index=True)
    pattern     = models.ForeignKey(Pattern, null=True, on_delete=models.PROTECT)

    @property
    def seconds(self):
        return (self.last_visit - self.first_visit).total_seconds()

    class Meta(UnManaged):
        db_table = "attrib_visit"

This model maps to a database table, which stores information about a visitor's session, such as the referrer where the visitor came from, how many pages they viewed, when they started viewing, when they stopped viewing, and they length of time they spent on the website.

Tastypie

Tastypie is an API framework for Django, which we use to build a RESTful API for retrieving information from the database.

For more information on how to create Tastypie resources, please see the documentation here.