class Instrument(models.Model): name = models.CharField(max_length=128, unique=True) description = models.CharField(max_length=255, null=True, blank=True) image = models.CharField(max_length=255, null=True, blank=True) def __unicode__(self): return self.name def __init__(self, *args, **kwargs): super(Instrument, self).__init__(*args, **kwargs) self.image_handler = ImageHandlerInstrument() if self.image: self.image_handler.load(self.image) @property def thumb_url(self): return self.image_handler.url('thumb') @property def icon_url(self): return self.image_handler.url('icon') @property def huge_url(self): return self.image_handler.url('huge') @property def is_vocal(self): return self.name.lower() == 'vocal'
def save(self): data = self.cleaned_data filename = generate_filename(data['image'].name) handler = ImageHandlerInstrument() handler.load(filename, data['image']) handler.save_thumbnails('PNG') instrument = Instrument.objects.create( name=data['name'], description=data.get('description'), image=filename ) self.instance = instrument
def __init__(self, *args, **kwargs): super(Instrument, self).__init__(*args, **kwargs) self.image_handler = ImageHandlerInstrument() if self.image: self.image_handler.load(self.image)