# -*- 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 . """ from django.contrib.auth.models import User from django.db import models class UserProfile(models.Model): user = models.OneToOneField( User, on_delete=models.CASCADE ) 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='+', on_delete=models.CASCADE ) idTeam2 = models.ForeignKey( Team, related_name='+', on_delete=models.CASCADE ) 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)) class Tipp(models.Model): matchID = models.ForeignKey( Match, on_delete=models.CASCADE ) tipperID = models.ForeignKey( User, on_delete=models.CASCADE ) 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, on_delete=models.CASCADE ) 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, on_delete=models.CASCADE ) competition = models.ForeignKey( Competition, on_delete=models.CASCADE ) points = models.PositiveSmallIntegerField() diff = models.SmallIntegerField() games = models.PositiveSmallIntegerField() class Meta: unique_together = ("team", "competition") class RelUserMandant(models.Model): user = models.ForeignKey( User, on_delete=models.CASCADE ) mandant = models.ForeignKey( Mandant, on_delete=models.CASCADE ) 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, on_delete=models.CASCADE ) class Meta: ordering = ['-created'] def __unicode__(self): return u'%s' % self.created class RelPostMandant(models.Model): post = models.ForeignKey( Post, on_delete=models.CASCADE ) mandant = models.ForeignKey( Mandant, on_delete=models.CASCADE ) class Meta: unique_together = ("post", "mandant") def __unicode__(self): return (str(self.post) + " -> " + str(self.mandant))