2016-06-08 21:22:23 +00:00
|
|
|
from django.contrib.sites.managers import CurrentSiteManager
|
2016-06-11 13:47:08 +00:00
|
|
|
from django.contrib.sites.models import Site
|
|
|
|
from django.db import models
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
from accounts.models import PonyConfSpeaker
|
2016-06-11 13:47:08 +00:00
|
|
|
from autoslug import AutoSlugField
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-11 13:47:08 +00:00
|
|
|
__all__ = ['Topic', 'Talk', 'Speach']
|
2016-06-07 20:59:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Topic(models.Model):
|
|
|
|
|
|
|
|
site = models.ForeignKey(Site, on_delete=models.CASCADE)
|
2016-06-08 21:22:23 +00:00
|
|
|
|
2016-06-07 20:59:13 +00:00
|
|
|
name = models.CharField(max_length=128, verbose_name='Name', unique=True)
|
|
|
|
slug = AutoSlugField(populate_from='name', unique=True)
|
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
objects = models.Manager()
|
|
|
|
on_site = CurrentSiteManager()
|
|
|
|
|
2016-06-07 20:59:13 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class Talk(models.Model):
|
|
|
|
|
|
|
|
site = models.ForeignKey(Site, on_delete=models.CASCADE)
|
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
speakers = models.ManyToManyField(PonyConfSpeaker, through='Speach')
|
2016-06-07 20:59:13 +00:00
|
|
|
title = models.CharField(max_length=128, verbose_name='Title')
|
|
|
|
slug = AutoSlugField(populate_from='title', unique=True)
|
|
|
|
description = models.TextField(blank=True, verbose_name='Description')
|
|
|
|
topics = models.ManyToManyField(Topic, blank=True)
|
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
objects = models.Manager()
|
|
|
|
on_site = CurrentSiteManager()
|
|
|
|
|
2016-06-07 20:59:13 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
|
|
|
|
class Speach(models.Model):
|
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
SPEAKER_NO = tuple((i, str(i)) for i in range(1, 8))
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-12 14:40:23 +00:00
|
|
|
speaker = models.ForeignKey(PonyConfSpeaker, on_delete=models.CASCADE)
|
2016-06-07 20:59:13 +00:00
|
|
|
talk = models.ForeignKey(Talk, on_delete=models.CASCADE)
|
|
|
|
order = models.IntegerField(choices=SPEAKER_NO)
|
|
|
|
|
|
|
|
class Meta:
|
2016-06-11 13:42:40 +00:00
|
|
|
ordering = ['talk', 'order']
|
2016-06-07 20:59:13 +00:00
|
|
|
unique_together = (
|
2016-06-12 14:40:23 +00:00
|
|
|
('speaker', 'talk'),
|
2016-06-07 20:59:13 +00:00
|
|
|
('order', 'talk'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def __str__(self):
|
2016-06-12 14:40:23 +00:00
|
|
|
return '%s speaking at %s in position %d' % (self.speaker, self.talk, self.order)
|
2016-06-11 15:28:39 +00:00
|
|
|
|
|
|
|
def username(self):
|
2016-06-12 14:40:23 +00:00
|
|
|
return self.speaker.user.username
|