Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean the Code #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions freepl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
# Create your models here.

#used for storing phone numbers and cumulative standings of each username
class fplUser(models.Model):
class FplUser(models.Model):
user = models.ForeignKey(User)
cumulativescore = models.IntegerField(default=0)
cumulativescore = models.IntegerField(default=0)

def __unicode__(self):
return (self.user.first_name+' '+self.user.last_name)

class teams(models.Model):
class Teams(models.Model):
country = models.CharField(max_length=20)
flag = models.ImageField(upload_to='countries/')
def __unicode__(self):
return self.country

class fixtures(models.Model):
class Fixtures(models.Model):
active = models.BooleanField(default=False)
locked = models.BooleanField(default=False)
teamA = models.ForeignKey(teams,related_name='teamA')
Expand All @@ -37,15 +37,15 @@ class fixtures(models.Model):

def __unicode__(self):
return '%s %s %s' % (self.teamA.country,self.teamB.country,self.date)

def save(self,*args,**kwargs):
if self.teamA==self.teamB:
raise ValidationError('Team A and Team B cannot be the same!')
else:
super(fixtures,self).save(*args,**kwargs)

class fixtureTeams(models.Model):
fixture = models.ForeignKey(fixtures)
class FixtureTeams(models.Model):
fixture = models.ForeignKey(fixtures)
user = models.ForeignKey(fplUser)
teamname = models.CharField(max_length=100)
teamconfig = models.CharField(max_length=700)
Expand All @@ -57,11 +57,11 @@ def __unicode__(self):
return '%s %s %s %s' % (self.user.user.first_name+' '+self.user.user.last_name,self.teamname,self.fixture.teamA.country,self.fixture.teamB.country)


class players(models.Model):
class Players(models.Model):
ROLES = (('bat', 'Batsmen'),('bowl','Bowler'),('wk','Wicket Keeper'),('allround','All Rounder'))
firstname = models.CharField(max_length=50)
lastname = models.CharField(max_length=50)
country = models.ForeignKey(teams)
country = models.ForeignKey(teams)
role = models.CharField(max_length=8, choices=ROLES)
netperformance = models.IntegerField(default=0)
price = models.PositiveSmallIntegerField()
Expand All @@ -72,10 +72,10 @@ def __unicode__(self):
#table is useless for displaying purpose in django admin
#But is heavily used for calculating scores for each team in a fixture

class playerstats(models.Model):
player = models.ForeignKey(players)
class Playerstats(models.Model):
player = models.ForeignKey(players)
fixture = models.ForeignKey(fixtures)
runsmade = models.PositiveSmallIntegerField(default=0)
runsmade = models.PositiveSmallIntegerField(default=0)
wickets = models.PositiveSmallIntegerField(default=0)
ballsfaced = models.PositiveSmallIntegerField(default=0)
fours = models.PositiveSmallIntegerField(default=0)
Expand All @@ -93,4 +93,3 @@ class playerstats(models.Model):

def __unicode__(self):
return '%s %s' % (self.player.firstname+' '+self.player.lastname,self.fixture.teamA.country+' '+self.fixture.teamB.country)