fromdjango.dbimportmodelsfromdjango.contrib.auth.modelsimportUserfromdjango.utils.textimportslugifyclassCustomComment(models.Model):owner=models.ForeignKey(User)username=models.CharField(max_length=80,blank=True)comment=models.TextField()posted=models.DateTimeField(auto_now_add=True)def__unicode__(self):returnu"%s"%self.usernamedefsave(self,**kwargs):self.username=self.owner.usernamereturnsuper(CustomComment,self).save(**kwargs)classEngineVersion(models.Model):codename=models.CharField(max_length=60,help_text='Codename for this version of the game engine.')released_on=models.DateField()version=models.DecimalField(blank=True,null=True,max_digits=4,decimal_places=2,help_text='Decimal version number of this version.')def__unicode__(self):returnu"%s"%self.codenameclassWriter(models.Model):owner=models.ForeignKey(User,blank=True,null=True,help_text='Is this writer part of this community?')known_as=models.CharField(max_length=80,blank=True,help_text='What name does this writer go by? Leave blank to use username.')bio=models.TextField(blank=True,help_text='Optional, but highly recommended.')def__unicode__(self):returnu"%s"%self.known_asdefsave(self,**kwargs):ifself.known_as=='':self.known_as=self.owner.usernamereturnsuper(Writer,self).save(**kwargs)classArtist(models.Model):owner=models.ForeignKey(User,blank=True,null=True,help_text='Is this artist part of this community?')known_as=models.CharField(max_length=80,blank=True,help_text='What name does this artist go by? Leave blank to use username.')bio=models.TextField(blank=True,help_text='Optional, but highly recommended.')website=models.URLField(blank=True,help_text='Does this artist have a online portfolio somewhere?')def__unicode__(self):returnu"%s"%self.known_asdefsave(self,**kwargs):ifself.known_as=='':self.known_as=self.owner.usernamereturnsuper(Artist,self).save(**kwargs)classComposer(models.Model):owner=models.ForeignKey(User,blank=True,null=True,help_text='Is this composer part of this community?')known_as=models.CharField(max_length=80,blank=True,help_text='What name does this composer go by? Leave blank to use username.')bio=models.TextField(blank=True,help_text='Optional, but highly recommended.')website=models.URLField(blank=True,help_text='Does this composer have a online portfolio somewhere?')def__unicode__(self):returnu"%s"%self.known_asdefsave(self,**kwargs):ifself.known_as=='':self.known_as=self.owner.usernamereturnsuper(Composer,self).save(**kwargs)classGameDownload(models.Model):GAME_WORKFLOW=((10,'Draft'),(20,'Demo'),(30,'Alpha'),(40,'Beta'),(200,'Final'),)game_file=models.FileField(upload_to='games',blank=True,null=True)#game_url = models.URLField(blank=True, null=True)title=models.CharField(max_length=128)version=models.PositiveIntegerField()classification=models.PositiveSmallIntegerField(choices=GAME_WORKFLOW,help_text='What classification does this release fall under?')is_public=models.BooleanField(default=True,help_text='Can anyone download this version?')beta_testers=models.ManyToManyField(User,blank=True,null=True,help_text='If this is not a public release, choose users who do have access.')changelog=models.TextField(blank=True,help_text='Detail any changes you may have done in this version -- optional.')download_count=models.PositiveIntegerField(default=0)release_date=models.DateField(auto_now_add=True)def__unicode__(self):return"%s%s%s"%(self.title,self.version,self.get_classification_display())classScreenshot(models.Model):image=models.ImageField(upload_to='game_screenshots')title=models.CharField(max_length=128,help_text='A title for this image?')is_public=models.BooleanField(default=True)is_title=models.BooleanField(help_text='Is this a title screen for the game?')added_on=models.DateField(auto_now_add=True)def__unicode__(self):returnu"%s"%self.titleclassGame(models.Model):TYPE_LIST=((10,'RPG Game'),(20,'Platformer'),(30,'Tech Demo'),(40,'Simulation'),(50,'Strategy'),(200,'Other'),)GENRE_LIST=((30,'Adventure'),(40,'Horror'),(50,'Humor'),(60,'Parody'),(70,'Fan Game'),(200,'Other'),)STYLE_LIST=(('Console styles',((10,'Old School NES'),(20,'Old School SNES'),)),('Unique Contrasts',((30,'Low contrast'),(40,'Bright and colorful'),(50,'2 color'),(60,'Shades of gray'),(70,'Cartoon like'),)),)title=models.CharField(max_length=128,help_text='Enter the title for your game here.')slug=models.SlugField(blank=True)owner=models.ForeignKey(User)author=models.CharField(max_length=80,blank=True)description=models.TextField(help_text='A description of your game to let others know what they will be playing. Be creative!')game_type=models.PositiveSmallIntegerField(choices=TYPE_LIST,help_text='Where does your game best fit in?')genre=models.PositiveSmallIntegerField(choices=GENRE_LIST,help_text='What genre is this game?')style=models.PositiveSmallIntegerField(choices=STYLE_LIST,help_text='What graphical style does your game use?')storyline=models.TextField(help_text='The introduction story of your game, different than the description.')scenario=models.ManyToManyField(Writer,help_text='Who wrote the scenario/story for this game?')graphics=models.ManyToManyField(Artist,help_text='Who drew the graphics you used in your game?')music=models.ManyToManyField(Composer,related_name='game_music_list',help_text='Who composed the music you used in your game?')sfx=models.ManyToManyField(Composer,related_name='game_sfx_list',help_text='Who created the sound effects you used in your game?')downloads=models.ManyToManyField(GameDownload,blank=True,null=True)screenshots=models.ManyToManyField(Screenshot,blank=True,null=True)engine=models.ForeignKey(EngineVersion,help_text='Which version of the engine was used to develop this game?')download_count=models.PositiveIntegerField(default=0)comments=models.ManyToManyField(CustomComment,blank=True,null=True)liked_by=models.ManyToManyField(User,blank=True,null=True,related_name='games_liked')disliked_by=models.ManyToManyField(User,blank=True,null=True,related_name='games_disliked')date_added=models.DateField(auto_now_add=True)updated_on=models.DateField(auto_now=True)def__unicode__(self):returnu"%s"%self.titledefsave(self,**kwargs):ifself.slug=='':self.slug=slugify(self.title)ifself.author=='':self.author=self.owner.usernamereturnsuper(Game,self).save(**kwargs)deffirst_screenshot(self):returnself.screenshots.all()[0].image.url@models.permalinkdefget_absolute_url(self):return('game_detail',[self.slug])