Commits

Yohan Boniface committed 7d11487

Move "color" to "options" (see yohanboniface/Leaflet.Storage#26)

  • Participants
  • Parent commits 0ea2ddb

Comments (0)

Files changed (10)

File leaflet_storage/base_models.py

 
 class Category(NamedModel):
     """
-    Category of a Marker.
+    Category of a Feature.
     """
     ICON_CLASS = (
         ('Default', 'Default'),
         null=True,
         verbose_name=_("description")
     )
-    color = models.CharField(
-        max_length=32,
-        default="DarkBlue",
-        help_text=_("Must be a CSS valid name (eg.: DarkBlue or #123456)"),
-        verbose_name=_("color")
-    )
+    options = DictField(blank=True, null=True, verbose_name=_("options"))
     pictogram = models.ForeignKey(
         Pictogram,
         null=True,
         return {
             "name": self.name,
             "pk": self.pk,
-            "color": self.color,
             "pictogram_url": self.pictogram.pictogram.url if self.pictogram else None,
             "icon_class": self.icon_class,
             "display_on_load": self.display_on_load,
+            "options": self.options,
         }
 
     @property
         null=True,
         verbose_name=_("description")
     )
-    color = models.CharField(
-        max_length=32,
-        blank=True,
-        null=True,
-        verbose_name=_("color"),
-        help_text=_("Optional. Uses category color if not set. "),
-    )
     category = models.ForeignKey(Category, verbose_name=_("category"))
+    options = DictField(blank=True, null=True, verbose_name=_("options"))
 
     objects = models.GeoManager()
 

File leaflet_storage/fields.py

         return simplejson.dumps(value)
 
     def to_python(self, value):
-        if value is None:
+        if not value:
             value = {}
         if isinstance(value, basestring):
             return simplejson.loads(value)

File leaflet_storage/forms.py

                 field.label = ""
 
 
+class OptionsForm(PlaceholderForm):
+    """
+    Manage options DictField.
+    """
+
+    PREFIX = "options_"
+
+    def __init__(self, *args, **kwargs):
+        self.options_data = {}
+        super(OptionsForm, self).__init__(*args, **kwargs)
+        for option_name, value in self.instance.options.iteritems():
+            option_name = "%s%s" % (self.PREFIX, option_name)
+            if option_name in self.fields:
+                self.fields[option_name].initial = value
+
+    def clean(self):
+        cleaned_data = self.cleaned_data
+        for field_name, value in cleaned_data.iteritems():
+            if field_name.startswith(self.PREFIX):
+                self.options_data[field_name[8:]] = value
+        return cleaned_data
+
+    def save(self, *args):
+        self.instance.options = self.options_data
+        return super(OptionsForm, self).save(*args)
+
+
 class QuickMapCreateForm(PlaceholderForm):
 
     def __init__(self, *args, **kwargs):
         fields = ('edit_status', 'editors')
 
 
-class CategoryForm(PlaceholderForm):
+class CategoryForm(OptionsForm):
+
+    options_color = forms.CharField(
+        required=False,
+        label=_('color'),
+        help_text=_("Must be a CSS valid name (eg.: DarkBlue or #123456)")
+    )
 
     class Meta:
         model = Category
         return features
 
 
-class FeatureForm(PlaceholderForm):
+class FeatureForm(OptionsForm):
+
+    options_color = forms.CharField(
+        required=False,
+        label=_('color'),
+        help_text=_("Optional. Uses category color if not set. ")
+    )
 
     class Meta:
         # model is added at runtime by the views
-        fields = ('name', 'description', 'color', 'category', 'latlng')
+        fields = ('name', 'description', 'category', 'latlng')
         widgets = {
             'latlng': forms.HiddenInput(),
         }

File leaflet_storage/migrations/0003_auto__add_field_polyline_options__add_field_category_options__add_fiel.py

+# -*- coding: utf-8 -*-
+from south.db import db
+from south.v2 import SchemaMigration
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'Polyline.options'
+        db.add_column('leaflet_storage_polyline', 'options',
+                      self.gf('leaflet_storage.fields.DictField')(null=True, blank=True),
+                      keep_default=False)
+
+        # Adding field 'Category.options'
+        db.add_column('leaflet_storage_category', 'options',
+                      self.gf('leaflet_storage.fields.DictField')(null=True, blank=True),
+                      keep_default=False)
+
+        # Adding field 'Polygon.options'
+        db.add_column('leaflet_storage_polygon', 'options',
+                      self.gf('leaflet_storage.fields.DictField')(null=True, blank=True),
+                      keep_default=False)
+
+        # Adding field 'Marker.options'
+        db.add_column('leaflet_storage_marker', 'options',
+                      self.gf('leaflet_storage.fields.DictField')(null=True, blank=True),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'Polyline.options'
+        db.delete_column('leaflet_storage_polyline', 'options')
+
+        # Deleting field 'Category.options'
+        db.delete_column('leaflet_storage_category', 'options')
+
+        # Deleting field 'Polygon.options'
+        db.delete_column('leaflet_storage_polygon', 'options')
+
+        # Deleting field 'Marker.options'
+        db.delete_column('leaflet_storage_marker', 'options')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'leaflet_storage.category': {
+            'Meta': {'ordering': "['rank']", 'object_name': 'Category'},
+            'color': ('django.db.models.fields.CharField', [], {'default': "'DarkBlue'", 'max_length': '32'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'display_on_load': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'icon_class': ('django.db.models.fields.CharField', [], {'default': "'Default'", 'max_length': '32'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'map': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Map']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'}),
+            'pictogram': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Pictogram']", 'null': 'True', 'blank': 'True'}),
+            'rank': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.licence': {
+            'Meta': {'object_name': 'Licence'},
+            'details': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+        },
+        'leaflet_storage.map': {
+            'Meta': {'object_name': 'Map'},
+            'center': ('django.contrib.gis.db.models.fields.PointField', [], {'geography': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'edit_status': ('django.db.models.fields.SmallIntegerField', [], {'default': '3'}),
+            'editors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'licence': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Licence']", 'on_delete': 'models.SET_DEFAULT'}),
+            'locate': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'owned_maps'", 'to': "orm['auth.User']"}),
+            'settings': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'tilelayers': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['leaflet_storage.TileLayer']", 'through': "orm['leaflet_storage.MapToTileLayer']", 'symmetrical': 'False'}),
+            'zoom': ('django.db.models.fields.IntegerField', [], {'default': '7'})
+        },
+        'leaflet_storage.maptotilelayer': {
+            'Meta': {'ordering': "['rank', 'tilelayer__name']", 'object_name': 'MapToTileLayer'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'map': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Map']"}),
+            'rank': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'tilelayer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.TileLayer']"})
+        },
+        'leaflet_storage.marker': {
+            'Meta': {'object_name': 'Marker'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'color': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.PointField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.pictogram': {
+            'Meta': {'object_name': 'Pictogram'},
+            'attribution': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'pictogram': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'})
+        },
+        'leaflet_storage.polygon': {
+            'Meta': {'object_name': 'Polygon'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'color': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.PolygonField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.polyline': {
+            'Meta': {'object_name': 'Polyline'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'color': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.LineStringField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.tilelayer': {
+            'Meta': {'object_name': 'TileLayer'},
+            'attribution': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'maxZoom': ('django.db.models.fields.IntegerField', [], {'default': '18'}),
+            'minZoom': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'url_template': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+        }
+    }
+
+    complete_apps = ['leaflet_storage']

File leaflet_storage/migrations/0004_migrate_color_to_options.py

+# -*- coding: utf-8 -*-
+from south.v2 import DataMigration
+
+
+class Migration(DataMigration):
+
+    def forwards(self, orm):
+        for obj in orm['leaflet_storage.Polyline'].objects.filter(color__isnull=False):
+            obj.options['color'] = obj.color
+            obj.save()
+
+        for obj in orm['leaflet_storage.Polygon'].objects.filter(color__isnull=False):
+            obj.options['color'] = obj.color
+            obj.save()
+
+        for obj in orm['leaflet_storage.Marker'].objects.filter(color__isnull=False):
+            obj.options['color'] = obj.color
+            obj.save()
+
+        for obj in orm['leaflet_storage.Category'].objects.filter(color__isnull=False):
+            obj.options['color'] = obj.color
+            obj.save()
+
+    def backwards(self, orm):
+        for obj in orm['leaflet_storage.Polyline'].objects.all():
+            if "color" in obj.options:
+                obj.color = obj.options['color']
+                obj.save()
+
+        for obj in orm['leaflet_storage.Polygon'].objects.all():
+            if "color" in obj.options:
+                obj.color = obj.options['color']
+                obj.save()
+
+        for obj in orm['leaflet_storage.Marker'].objects.all():
+            if "color" in obj.options:
+                obj.color = obj.options['color']
+                obj.save()
+
+        for obj in orm['leaflet_storage.Category'].objects.all():
+            if "color" in obj.options:
+                obj.color = obj.options['color']
+                obj.save()
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'leaflet_storage.category': {
+            'Meta': {'ordering': "['rank']", 'object_name': 'Category'},
+            'color': ('django.db.models.fields.CharField', [], {'default': "'DarkBlue'", 'max_length': '32'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'display_on_load': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'icon_class': ('django.db.models.fields.CharField', [], {'default': "'Default'", 'max_length': '32'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'map': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Map']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'}),
+            'pictogram': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Pictogram']", 'null': 'True', 'blank': 'True'}),
+            'rank': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.licence': {
+            'Meta': {'object_name': 'Licence'},
+            'details': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+        },
+        'leaflet_storage.map': {
+            'Meta': {'object_name': 'Map'},
+            'center': ('django.contrib.gis.db.models.fields.PointField', [], {'geography': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'edit_status': ('django.db.models.fields.SmallIntegerField', [], {'default': '3'}),
+            'editors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'licence': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Licence']", 'on_delete': 'models.SET_DEFAULT'}),
+            'locate': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'owned_maps'", 'to': "orm['auth.User']"}),
+            'settings': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'tilelayers': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['leaflet_storage.TileLayer']", 'through': "orm['leaflet_storage.MapToTileLayer']", 'symmetrical': 'False'}),
+            'zoom': ('django.db.models.fields.IntegerField', [], {'default': '7'})
+        },
+        'leaflet_storage.maptotilelayer': {
+            'Meta': {'ordering': "['rank', 'tilelayer__name']", 'object_name': 'MapToTileLayer'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'map': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Map']"}),
+            'rank': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'tilelayer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.TileLayer']"})
+        },
+        'leaflet_storage.marker': {
+            'Meta': {'object_name': 'Marker'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'color': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.PointField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.pictogram': {
+            'Meta': {'object_name': 'Pictogram'},
+            'attribution': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'pictogram': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'})
+        },
+        'leaflet_storage.polygon': {
+            'Meta': {'object_name': 'Polygon'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'color': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.PolygonField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.polyline': {
+            'Meta': {'object_name': 'Polyline'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'color': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.LineStringField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.tilelayer': {
+            'Meta': {'object_name': 'TileLayer'},
+            'attribution': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'maxZoom': ('django.db.models.fields.IntegerField', [], {'default': '18'}),
+            'minZoom': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'url_template': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+        }
+    }
+
+    complete_apps = ['leaflet_storage']
+    symmetrical = True

File leaflet_storage/migrations/0005_auto__del_field_polyline_color__del_field_category_color__del_field_po.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Deleting field 'Polyline.color'
+        db.delete_column('leaflet_storage_polyline', 'color')
+
+        # Deleting field 'Category.color'
+        db.delete_column('leaflet_storage_category', 'color')
+
+        # Deleting field 'Polygon.color'
+        db.delete_column('leaflet_storage_polygon', 'color')
+
+        # Deleting field 'Marker.color'
+        db.delete_column('leaflet_storage_marker', 'color')
+
+
+    def backwards(self, orm):
+        # Adding field 'Polyline.color'
+        db.add_column('leaflet_storage_polyline', 'color',
+                      self.gf('django.db.models.fields.CharField')(max_length=32, null=True, blank=True),
+                      keep_default=False)
+
+        # Adding field 'Category.color'
+        db.add_column('leaflet_storage_category', 'color',
+                      self.gf('django.db.models.fields.CharField')(default='DarkBlue', max_length=32),
+                      keep_default=False)
+
+        # Adding field 'Polygon.color'
+        db.add_column('leaflet_storage_polygon', 'color',
+                      self.gf('django.db.models.fields.CharField')(max_length=32, null=True, blank=True),
+                      keep_default=False)
+
+        # Adding field 'Marker.color'
+        db.add_column('leaflet_storage_marker', 'color',
+                      self.gf('django.db.models.fields.CharField')(max_length=32, null=True, blank=True),
+                      keep_default=False)
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'leaflet_storage.category': {
+            'Meta': {'ordering': "['rank']", 'object_name': 'Category'},
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'display_on_load': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'icon_class': ('django.db.models.fields.CharField', [], {'default': "'Default'", 'max_length': '32'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'map': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Map']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'}),
+            'pictogram': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Pictogram']", 'null': 'True', 'blank': 'True'}),
+            'rank': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.licence': {
+            'Meta': {'object_name': 'Licence'},
+            'details': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+        },
+        'leaflet_storage.map': {
+            'Meta': {'object_name': 'Map'},
+            'center': ('django.contrib.gis.db.models.fields.PointField', [], {'geography': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'edit_status': ('django.db.models.fields.SmallIntegerField', [], {'default': '3'}),
+            'editors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'licence': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Licence']", 'on_delete': 'models.SET_DEFAULT'}),
+            'locate': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'owned_maps'", 'to': "orm['auth.User']"}),
+            'settings': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'tilelayers': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['leaflet_storage.TileLayer']", 'through': "orm['leaflet_storage.MapToTileLayer']", 'symmetrical': 'False'}),
+            'zoom': ('django.db.models.fields.IntegerField', [], {'default': '7'})
+        },
+        'leaflet_storage.maptotilelayer': {
+            'Meta': {'ordering': "['rank', 'tilelayer__name']", 'object_name': 'MapToTileLayer'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'map': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Map']"}),
+            'rank': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'tilelayer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.TileLayer']"})
+        },
+        'leaflet_storage.marker': {
+            'Meta': {'object_name': 'Marker'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.PointField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.pictogram': {
+            'Meta': {'object_name': 'Pictogram'},
+            'attribution': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'pictogram': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'})
+        },
+        'leaflet_storage.polygon': {
+            'Meta': {'object_name': 'Polygon'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.PolygonField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.polyline': {
+            'Meta': {'object_name': 'Polyline'},
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['leaflet_storage.Category']"}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latlng': ('django.contrib.gis.db.models.fields.LineStringField', [], {'geography': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'options': ('leaflet_storage.fields.DictField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'leaflet_storage.tilelayer': {
+            'Meta': {'object_name': 'TileLayer'},
+            'attribution': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'maxZoom': ('django.db.models.fields.IntegerField', [], {'default': '18'}),
+            'minZoom': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'url_template': ('django.db.models.fields.CharField', [], {'max_length': '200'})
+        }
+    }
+
+    complete_apps = ['leaflet_storage']

File leaflet_storage/tests/base.py

     map = factory.SubFactory(MapFactory)
     name = "test category"
     description = "test description"
-    color = "DarkRed"
     display_on_load = True
     rank = 1
 
     ABSTRACT_FACTORY = True
     name = "test feature"
     description = "test description"
-    color = None  # Having a color on a feature is not the normal case
     category = factory.SubFactory(CategoryFactory)
 
 

File leaflet_storage/tests/fields.py

             d
         )
 
+    def test_can_set_item(self):
+        d = {'locateControl': True}
+        self.map.settings = d
+        self.map.save()
+        map_inst = Map.objects.get(pk=self.map.pk)
+        map_inst.settings['color'] = 'DarkGreen'
+        self.assertEqual(
+            map_inst.settings['locateControl'],
+            True
+        )
+
     def test_should_return_a_dict_if_none(self):
         self.map.settings = None
         self.map.save()

File leaflet_storage/tests/views.py

         self.assertEqual(Marker.objects.filter(category=self.category, name="London").count(), 1)
         marker = Marker.objects.get(category=self.category, name="London")
         self.assertEqual(marker.description, "London description")
-        self.assertEqual(marker.color, "Pink")
+        self.assertEqual(marker.options["color"], "Pink")
         self.assertEqual(Marker.objects.filter(category=self.category, name="Antwerpen").count(), 1)
         marker = Marker.objects.get(category=self.category, name="Antwerpen")
         self.assertEqual(marker.description, "")
-        self.assertEqual(marker.color, None)
+        self.assertFalse("color" in marker.options)
 
     def test_GeoJSON_empty_coordinates_should_not_be_imported(self):
         self.assertEqual(Marker.objects.filter(category=self.category).count(), 0)

File leaflet_storage/views.py

             'LineString': Polyline,
             'Polygon': Polygon
         }
-        # Use a tuple to add more source possible
+        # Use a tuple to add more sources possible
         # first item is field name
         FIELDS = [
             ('name', 'title'),
                     candidates = [field]
                 for candidate in candidates:
                     if candidate in feature.properties:
-                        kwargs[name] = feature.properties[candidate]
+                        value = feature.properties[candidate]
+                        if name in klass._meta.get_all_field_names():
+                            kwargs[name] = value
+                        else:
+                            # it's an option
+                            if not "options" in kwargs:
+                                kwargs['options'] = {}
+                            kwargs['options'][name] = value
                         break
             try:
                 klass.objects.create(**kwargs)
 
     def geojson(self, context):
         qs = self.get_queryset()
-        djf = django.Django(geodjango="latlng", properties=['name', 'category_id', 'color'])
+        djf = django.Django(geodjango="latlng", properties=['name', 'category_id', 'options'])
         geoj = geojson.GeoJSON()
         return geoj.encode(djf.decode(qs), to_string=False)