diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-08-25 17:35:32 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-08-25 17:35:32 +0200 | 
| commit | 62d12b1e348323e0acd3f76026defce9aab4e5e0 (patch) | |
| tree | 54218f760a4955d071f934a54811a2be9778894e /archaeological_finds/models.py | |
| parent | 255e494370e287c0d0fc78131c4d56e7d805cadb (diff) | |
| download | Ishtar-62d12b1e348323e0acd3f76026defce9aab4e5e0.tar.bz2 Ishtar-62d12b1e348323e0acd3f76026defce9aab4e5e0.zip | |
Add images to finds (refs #1314)
* an abstract model class has been defined to manage image and thumbnail
  with resizing on the fly
* max size for images and thumbnails are set in project settings
* new field have been added to Find model to save images and thumbnails
* form and wizard of Find have been changed
Diffstat (limited to 'archaeological_finds/models.py')
| -rw-r--r-- | archaeological_finds/models.py | 17 | 
1 files changed, 14 insertions, 3 deletions
| diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index 4b1e95e34..8fb18385b 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2012 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2012-2013 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet>  # This program is free software: you can redistribute it and/or modify  # it under the terms of the GNU Affero General Public License as @@ -22,7 +22,7 @@ from django.contrib.gis.db import models  from django.db.models import Max  from django.utils.translation import ugettext_lazy as _, ugettext -from ishtar_common.models import GeneralType, BaseHistorizedItem, \ +from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \                LightHistorizedItem, HistoricalRecords, OwnPerms, Source, Person  from archaeological_operations.models import AdministrativeAct @@ -130,7 +130,7 @@ class BaseFind(BaseHistorizedItem, OwnPerms):                             self.context_record.label,                             lbl) if it]) -class Find(BaseHistorizedItem, OwnPerms): +class Find(BaseHistorizedItem, ImageModel, OwnPerms):      TABLE_COLS = ['label', 'material_type', 'dating.period',                    'base_finds.context_record.parcel.town',                    'base_finds.context_record.operation.year', @@ -145,6 +145,10 @@ class Find(BaseHistorizedItem, OwnPerms):      order = models.IntegerField(_(u"Order"))      label = models.CharField(_(u"ID"), max_length=60)      description = models.TextField(_(u"Description"), blank=True, null=True) +    """ +    image = models.ImageField(upload_to="finds/", blank=True, null=True) +    thumbnail = models.ImageField(upload_to='finds/thumbs/', blank=True, +                                  null=True)"""      material_type = models.ForeignKey(MaterialType,                                verbose_name = _(u"Material type"))      volume = models.FloatField(_(u"Volume (l)"), blank=True, null=True) @@ -160,6 +164,13 @@ class Find(BaseHistorizedItem, OwnPerms):                                    blank=True, null=True, related_name='finds')      history = HistoricalRecords() +    def __init__(self, *args, **kwargs): +        super(Find, self).__init__(*args, **kwargs) +        image = self._meta.get_field_by_name("image")[0] +        image.upload_to = "finds/" +        thumbnail = self._meta.get_field_by_name("thumbnail")[0] +        thumbnail.upload_to = "finds/thumbs/" +      @classmethod      def get_years(cls):          years = set() | 
