Source

indie-community / gamedb / models.py

Diff from to

gamedb/models.py

 from django.db import models
+from django.contrib.auth.models import User
+from django.utils.text import slugify
 
-# Create your models here.
+class CustomComment(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):
+        return u"%s" % self.username
+    def save(self, commit=True):
+        self.username = self.owner.username
+        return super(CustomComment, self).save(commit)
+
+class EngineVersion(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):
+        return u"%s" % self.codename
+
+class Writer(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):
+        return u"%s" % self.known_as
+    def save(self, commit=True):
+        if self.known_as == '':
+            self.known_as = self.owner.username
+        return super(Writer, self).save(commit)
+
+class Artist(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):
+        return u"%s" % self.known_as
+    def save(self, commit=True):
+        if self.known_as == '':
+            self.known_as = self.owner.username
+        return super(Artist, self).save(commit)
+
+class Composer(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):
+        return u"%s" % self.known_as
+    def save(self, commit=True):
+        if self.known_as == '':
+            self.known_as = self.owner.username
+        return super(Composer, self).save(commit)
+
+class GameDownload(models.Model):
+    GAME_WORKFLOW = (
+        (10, 'Draft'),
+        (20, 'Demo'),
+        (30, 'Alpha'),
+        (40, 'Beta'),
+        (200, 'Final'),
+    )
+    game_file = models.FileField(upload_to='games')
+    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())
+
+class Screenshot(models.Model):
+    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):
+        return u"%s" % self.title
+
+class Game(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):
+        return u"%s" % self.title
+    def save(self, commit=True):
+        if self.slug == '':
+            self.slug = slugify(self.title)
+        if self.author == '':
+            self.author = self.owner.username
+        return super(Game, self).save(commit)