Source

indie-community / gamedb / models.py

Kevin Veroneau 67b36ce 
Kevin Veroneau 8ce5000 

Kevin Veroneau 67b36ce 
Kevin Veroneau 8ce5000 






Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 
Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 













Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 

Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 







Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 

Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 







Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 

Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 





















Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 




























































Kevin Veroneau 09fd8ca 
Kevin Veroneau 8ce5000 



Kevin Veroneau 09fd8ca 
from django.db import models
from django.contrib.auth.models import User
from django.utils.text import slugify

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, **kwargs):
        self.username = self.owner.username
        return super(CustomComment, self).save(**kwargs)

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, **kwargs):
        if self.known_as == '':
            self.known_as = self.owner.username
        return super(Writer, self).save(**kwargs)

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, **kwargs):
        if self.known_as == '':
            self.known_as = self.owner.username
        return super(Artist, self).save(**kwargs)

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, **kwargs):
        if self.known_as == '':
            self.known_as = self.owner.username
        return super(Composer, self).save(**kwargs)

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):
    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):
        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, **kwargs):
        if self.slug == '':
            self.slug = slugify(self.title)
        if self.author == '':
            self.author = self.owner.username
        return super(Game, self).save(**kwargs)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.