multistream/frontend/models.py
File Type: text/x-script.python
#models
from datetime import datetime
from django.db import models
from django.utils.timezone import now
from colorfield.fields import ColorField
class Channel(models.Model):
name = models.CharField(max_length=60)
active = models.BooleanField(default=True)
communities = models.ManyToManyField('Community',related_name='channels',blank=True)
logo = models.URLField(blank=True, editable=False)
preview = models.URLField(blank=True, editable=False)
game = models.CharField(max_length=60,blank=True, editable=False)
live = models.BooleanField(default=False, editable=False)
tid = models.CharField(max_length=16,blank=True, editable=False)
viewer_count = models.IntegerField(default=0, editable=False)
last_saved = models.DateTimeField(default = now, blank=True, editable=False)
def __str__(self):
return self.name
def image(self):
if self.live:
return self.preview
else:
return self.logo
def age_in_seconds(self):
return (now() - self.last_saved).total_seconds()
class Community(models.Model):
name = models.CharField(max_length=30)
active = models.BooleanField(default=True)
index = models.IntegerField(default=0)
domain = models.CharField(max_length=255, blank=True)
home_url = models.CharField(max_length=255, blank=True)
featured = models.BooleanField(default=False)
logo_url = models.CharField(max_length=255, blank=True)
background_url = models.CharField(max_length=255, blank=True)
background_size = models.CharField(max_length=7, blank=True, default="cover", choices=(("cover","Cover"),("contain","Contain"),("auto","Auto")))
background_position_x = models.CharField(max_length=6, blank=True, default="center", choices=(("left","Left"),("center","Center"),("right","Right")))
background_position_y = models.CharField(max_length=6, blank=True, default="center", choices=(("top","Top"),("center","Center"),("bottom","Bottom")))
header_bg_color = ColorField(default="#000000")
body_bg_color = ColorField(default="#000000")
class Meta:
verbose_name_plural = "communities"
def __str__(self):
return self.name
def slug(self):
return self.name.replace(' ','-').lower()