diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-08-19 16:21:27 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-08-19 16:21:27 +0200 |
commit | c8fcf14626873ad4bbe91788aadb60cfa488beda (patch) | |
tree | 679daba9ee80e429aec05a7f30f64e19d2237616 /chimere/models.py | |
parent | 647f527cf506b362ff02ddf58da2490768b8bf7a (diff) | |
download | Chimère-c8fcf14626873ad4bbe91788aadb60cfa488beda.tar.bz2 Chimère-c8fcf14626873ad4bbe91788aadb60cfa488beda.zip |
Models: Automaticaly add read attributes for marker properties
Diffstat (limited to 'chimere/models.py')
-rw-r--r-- | chimere/models.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/chimere/models.py b/chimere/models.py index c053e1b..27875ec 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -25,6 +25,7 @@ import simplejson as json from lxml import etree from datetime import datetime, timedelta from subprocess import Popen, PIPE +import unidecode from django.conf import settings from django.contrib.gis.db import models @@ -301,6 +302,15 @@ class Marker(GeographicItem): def __unicode__(self): return self.name + def __init__(self, *args, **kwargs): + super(Marker, self).__init__(*args, **kwargs) + # add read attributes for properties + for property in self.getProperties(): + attr_name = unidecode.unidecode(property.propertymodel.name).lower() + attr_name = re.sub(r'\W+','_', attr_name.strip()) + if not hasattr(self, attr_name): + setattr(self, attr_name, property.value) + def get_init_multi(self): multis = [forms.model_to_dict(multi) for multi in self.multimedia_files.all()] |