135 lines
4.3 KiB
Python
135 lines
4.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Copyright (c) 2015-2016 by Martin Bley (martin@mb-oss.de)
|
|
|
|
This file is part of TipPy.
|
|
|
|
TipPy is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
TipPy is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with TipPy. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
from django.db import models
|
|
from django.core.urlresolvers import reverse
|
|
from django.contrib.auth.models import User
|
|
|
|
class UserProfile(models.Model):
|
|
user = models.OneToOneField(User)
|
|
avatar = models.ImageField(upload_to="profiles/", blank=True)
|
|
|
|
def __unicode__(self):
|
|
return self.user.username
|
|
|
|
class Competition(models.Model):
|
|
leagueShortcut = models.CharField(max_length=32)
|
|
leagueName = models.CharField(max_length=128)
|
|
season = models.CharField(max_length=4)
|
|
|
|
def __unicode__(self):
|
|
return(self.leagueShortcut)
|
|
|
|
class Team(models.Model):
|
|
teamID = models.IntegerField(unique=True, primary_key=True)
|
|
name = models.CharField(max_length=200)
|
|
icon = models.FileField(upload_to="images/team_logos/")
|
|
abbr = models.CharField(max_length=3)
|
|
iconURL = models.CharField(max_length=2000)
|
|
|
|
def __unicode__(self):
|
|
return self.name
|
|
|
|
class Meta:
|
|
managed = True
|
|
app_label = 'tipp'
|
|
|
|
|
|
class Match(models.Model):
|
|
matchID = models.IntegerField(unique=True,primary_key=True)
|
|
matchDateTime = models.DateTimeField()
|
|
group = models.IntegerField()
|
|
matchday = models.IntegerField()
|
|
matchday_name = models.CharField(max_length=128)
|
|
idTeam1 = models.ForeignKey(Team, related_name='+')
|
|
idTeam2 = models.ForeignKey(Team, related_name='+')
|
|
pointsTeam1 = models.SmallIntegerField()
|
|
pointsTeam2 = models.SmallIntegerField()
|
|
finished = models.BooleanField()
|
|
season = models.CharField(max_length=4)
|
|
leagueShortcut = models.CharField(max_length=12)
|
|
|
|
def __unicode__(self):
|
|
"""
|
|
return (str(self.matchID) +
|
|
str(Team.objects.get(teamID=int(self.idTeam1)).values(name)) + " - " +
|
|
str(Team.objects.get(teamID=int(self.idTeam2)).values(name)))
|
|
"""
|
|
return (str(self.matchID))
|
|
|
|
class Tipp(models.Model):
|
|
matchID = models.ForeignKey(Match)
|
|
tipperID = models.ForeignKey(User)
|
|
pointsTeam1 = models.PositiveSmallIntegerField()
|
|
pointsTeam2 = models.PositiveSmallIntegerField()
|
|
score = models.PositiveIntegerField(blank=True, null=True)
|
|
|
|
class Meta:
|
|
unique_together = ("matchID", "tipperID")
|
|
|
|
class Mandant(models.Model):
|
|
name = models.CharField(max_length=32, unique=True)
|
|
description = models.CharField(max_length=255)
|
|
def __unicode__(self):
|
|
return self.name
|
|
|
|
class Score(models.Model):
|
|
client = models.ForeignKey(Mandant)
|
|
exact_high = models.PositiveSmallIntegerField()
|
|
exact = models.PositiveSmallIntegerField()
|
|
diff = models.PositiveSmallIntegerField()
|
|
tendency = models.PositiveSmallIntegerField()
|
|
def __unicode__(self):
|
|
return str(self.client)
|
|
|
|
class chart(models.Model):
|
|
team = models.ForeignKey(Team)
|
|
competition = models.ForeignKey(Competition)
|
|
points = models.PositiveSmallIntegerField()
|
|
diff = models.SmallIntegerField()
|
|
games = models.PositiveSmallIntegerField()
|
|
|
|
class Meta:
|
|
unique_together = ("team", "competition")
|
|
|
|
class RelUserMandant(models.Model):
|
|
user = models.ForeignKey(User)
|
|
mandant = models.ForeignKey(Mandant)
|
|
|
|
class Meta:
|
|
unique_together = ("user", "mandant")
|
|
def __unicode__(self):
|
|
return (str(self.user) + " -> " + str(self.mandant))
|
|
|
|
class Post(models.Model):
|
|
content = models.TextField()
|
|
published = models.BooleanField(default=True)
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
author = models.ForeignKey(User)
|
|
mandant = models.ForeignKey(Mandant)
|
|
|
|
class Meta:
|
|
ordering = ['-created']
|
|
|
|
def __unicode__(self):
|
|
return u'%s' % self.created
|
|
|
|
|