Public feed #894332

Anonymous

public python v1 · immutable
Raw Edit
·published 2008-02-06 21:34 UTC
rendered paste body
#import multilingualfrom django.db import modelsfrom django.db.models.loading import get_modelimport reTYPE_IN_DESIGN_CHOICES=(        ('FS', 'Flat Screen'),        ('RC', 'Rotocolor'),        ('RG', 'RGB'),)# return the maximum + 1 value of the code_name escaping any characterdef voodoo_magic():        return max([                        int (                                [ group if group.isdigit() else '' for group in re.match('([a-zA-Z_-]*)([0-9]+)([a-zA-Z_-]*)',bin.code_name).groups()][1]                                ) for bin in get_model('designs','Design').objects.all()]) + 1 class Design(models.Model):        linked_product = models.ForeignKey('self',unique=True,blank=True,null=True)        create_date = models.DateField(auto_now=True)        update_date = models.DateField(auto_now_add=True)        code_name = models.CharField(max_length=20,unique=True,default = lambda: voodoo_magic())        internal_code_name = models.CharField(max_length=20,unique=True)        design_type = models.CharField(choices=TYPE_IN_DESIGN_CHOICES,max_length=2)        dpi = models.IntegerField(max_length=4)        enabled = models.BooleanField()        image_thumb = models.ImageField(upload_to='image_thumbs')        scale_1to1_preview = models.ImageField(upload_to='images_1to1_preview')        archive = models.FileField(upload_to='products',null=True)        def __str__(self):                return self.code_name        # helper method for visualization in list        def image_thumbnail(self):                return '<img src="%s" />' % self.get_image_thumb_url()        image_thumbnail.allow_tags = True         def image_scale(self):                return '<img src="%s" />' % self.get_scale_1to1_preview_url()        image_scale.allow_tags = True        #############        class Admin:                list_display = ('code_name','create_date','design_type','image_thumbnail','enabled','image_scale')                fields = (                                (None,{                                        'classes': 'wide',                                        'fields': (('code_name','internal_code_name'),'enabled','dpi','design_type','linked_product','archive'),                                }),                                ('Images',{                                        'fields':('image_thumb','scale_1to1_preview'),                                }),                        )                list_filter = ('design_type','dpi','enabled',)                search_fields = ('description',)class Preview(models.Model):        belong_Design = models.ForeignKey(Design,edit_inline=models.TABULAR)        image_preview = models.ImageField(upload_to='images_preview',core=True)class Color_preview(models.Model):        belong_Design = models.ForeignKey(Design,edit_inline=models.TABULAR)        image_color = models.ImageField(upload_to='image_color_preview',core=True)