示例#1
0
class Varuosa(models.Model):
    varuosa_id = models.PositiveIntegerField(primary_key=True,
                                             default=next_varuosa_id)
    artikli_nr = models.CharField(max_length=50,
                                  unique=True,
                                  default=next_artikli_nr)
    tukihind = models.DecimalField(default=0.0,
                                   max_digits=10,
                                   decimal_places=2)
    kogus = models.PositiveSmallIntegerField(default=0)
    katalogi_nr = models.CharField(max_length=50, blank=True, null=True)
    monteerimis_koht = models.CharField(max_length=100, blank=True, null=True)
    mootmed = models.CharField(max_length=50, blank=True, null=True)
    kirjeldus = models.TextField(blank=True, null=True)

    varuosa_kategooria = models.ForeignKey(Varuosa_kategooria)
    varuosa_kulg = models.ForeignKey(Varuosa_kulg, blank=True, null=True)
    varuosa_seisund = models.ForeignKey(Varuosa_seisund, default=1)
    tootja = models.ForeignKey(Tootja)

    auto_modifikatsioonid = models.ManyToManyField(Auto_modifikatsioon)

    pilt = models.ImageField(
        null=True,
        blank=True,
        upload_to='img_varuosad/',
        storage=DatabaseStorage(options=settings.DBS_OPTIONS),
        default='img_varuosad/default_varuosa.png')

    def __unicode__(self):
        return self.artikli_nr

    def save(self, *args, **kwargs):
        from django.core.exceptions import ValidationError
        try:
            self.clean()
        except ValidationError:
            raise
        # Call the "real" save() method.s
        super(Varuosa, self).save(*args, **kwargs)

    def clean(self):
        from django.core.exceptions import ValidationError
        import re
        # Don't allow draft entries to have a pub_date.
        pattern = re.compile('^ALM-[\d]+[a-zA-Z]*')
        if not pattern.match(self.artikli_nr):
            raise ValidationError(
                'Artikli nr. should be like ALM-x, where x is any digit')
        if self.tukihind < 0:
            raise ValidationError('Tukihind should be positive number')

    class Meta:
        ordering = ['artikli_nr']
        unique_together = (("artikli_nr", "varuosa_kategooria"), )
        verbose_name_plural = "varuosad"
示例#2
0
def image_exists(filename):
    """Check if image filename exists in the database."""
    # Read file from database
    storage = DatabaseStorage(options=ImageDraw.DBS_OPTIONS)
    # Check all namespaces
    check_single = storage.open('single/' + filename, 'rb')
    check_relation = storage.open('relation/' + filename, 'rb')
    check_schema = storage.open('schema/' + filename, 'rb')

    if check_single or check_relation or check_schema:
        return True
    return False
示例#3
0
class SingleImageDraw(ImageDraw):
    number = models.CharField(max_length=20, primary_key=True)
    denomination = models.CharField(max_length=80, null=True)
    image = models.ImageField(
        null=True,
        blank=True,
        upload_to='single/',
        storage=DatabaseStorage(options=ImageDraw.DBS_OPTIONS))

    def __unicode__(self):
        return u'%s' % self.number

    class Meta:
        ordering = ('number', )
示例#4
0
class SchemaImageDraw(ImageDraw):
    reference = models.CharField(max_length=20, primary_key=True)
    model = models.CharField(max_length=20)

    image = models.ImageField(
        null=True,
        blank=True,
        upload_to='schema/',
        storage=DatabaseStorage(options=ImageDraw.DBS_OPTIONS))

    def __unicode__(self):
        return u'%s' % self.reference

    class Meta:
        ordering = ('reference', )
示例#5
0
class RelationImageDraw(ImageDraw):
    # Only for RelationImageDraw.
    DRAW_TYPE = (('H', 'Horizontal'), ('V', 'Vertical'))

    code = models.CharField(max_length=20, primary_key=True)
    reference = models.CharField(max_length=20)
    type = models.CharField(max_length=1, choices=DRAW_TYPE)

    image = models.ImageField(
        null=True,
        blank=True,
        upload_to='relation/',
        storage=DatabaseStorage(options=ImageDraw.DBS_OPTIONS))

    def __unicode__(self):
        return u'%s' % self.code

    class Meta:
        ordering = ('reference', )
示例#6
0
class File(models.Model):
    Nom = models.TextField(null=True, blank=True)
    Size = models.FloatField(null=True, blank=True)
    Binary = models.FileField(upload_to="file",
                              storage=DatabaseStorage(settings.DB_FILES))
    Date = models.DateField(null=True, blank=True)