User:Darija Medic/technicalcourse/django

From XPUB & Lens-Based wiki

preliminary version of models

class Tag(models.Model):
    name = models.CharField(max_length=255)
    # pieces = ...
    def __unicode__(self):
        return self.name

class Piece(models.Model):
    title = models.CharField(max_length=255, blank=True)
    year_built= models.IntegerField(null=True, blank=True)
    torn_down= models.IntegerField(null=True, blank=True)
    description = models.TextField(blank=True)
    image=models.ImageField(upload_to="images")
    footnote=models.CharField(max_length=255, blank=True)

    sounds=models.ManyToManyField("Zvuk", related_name="pieces", blank=True)
    tags = models.ManyToManyField("Tag", related_name="pieces", blank = True)  
    def __unicode__(self):
        return self.title      

class Pic(models.Model):
    piece=models.ForeignKey("Piece", related_name="pics")
    image=ImageWithThumbnailsField(
        upload_to='images',
        thumbnail={'size': (120, 120)},
        extra_thumbnails={
            'icon': {'size': (32, 32), 'options': ['crop', 'upscale']},
            'large': {'size': (640, 640)},
        }
    )

    def __unicode__(self):
        return self.image.name

class Zvuk(models.Model):
    fajl=models.FileField(upload_to="zvuks")
    def __unicode__(self):
        return self.fajl.name