Repository: City-of-Helsinki/linkedevents

Issue:
Add place to django-admin



Discussion:

Resolving patch:
diff --git a/events/admin.py b/events/admin.py
--- a/events/admin.py
+++ b/events/admin.py
@@ -1,3 +1,4 @@
+from django.conf import settings
 from django.contrib import admin
 from django.contrib.admin.widgets import FilteredSelectMultiple
 from django.contrib.gis import admin as geoadmin
@@ -5,6 +6,7 @@
 from django.utils.translation import ugettext as _
 from modeltranslation.admin import TranslationAdmin
 from reversion.admin import VersionAdmin
+from events.api import generate_id
 from events.models import Event, Keyword, Place, Language, \
     OpeningHoursSpecification, KeywordLabel, Organization, License
 
@@ -30,7 +32,27 @@ class KeywordAdmin(BaseAdmin, TranslationAdmin, VersionAdmin):
 
 class PlaceAdmin(geoadmin.GeoModelAdmin, BaseAdmin, TranslationAdmin,
                  VersionAdmin):
-    pass
+    fieldsets = (
+        (None, {
+            'fields': ('publisher', 'name', 'description', 'info_url', 'position', 'parent')
+
+        }),
+        (_('Contact info'), {
+            'fields':  ('email', 'telephone', 'contact_type', 'street_address', 'address_locality', 'address_region',
+                        'postal_code', 'post_office_box_num')
+        }),
+    )
+
+    def save_model(self, request, obj, form, change):
+        system_id = settings.SYSTEM_DATA_SOURCE_ID
+        obj.data_source_id = system_id
+        if not obj.id:
+            obj.id = generate_id(system_id)
+        obj.origin_id = obj.id.split(':')[1]
+
+        super().save_model(request, obj, form, change)
+
+admin.site.register(Place, PlaceAdmin)
 
 
 class OrganizationAdmin(BaseAdmin):
diff --git a/events/migrations/0026_minor_changes.py b/events/migrations/0026_minor_changes.py
new file mode 100644
--- /dev/null
+++ b/events/migrations/0026_minor_changes.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.6 on 2016-07-05 13:45
+from __future__ import unicode_literals
+
+import django.contrib.postgres.fields.hstore
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('events', '0025_add_license_model'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='event',
+            name='custom_data',
+            field=django.contrib.postgres.fields.hstore.HStoreField(blank=True, null=True),
+        ),
+        migrations.AlterField(
+            model_name='place',
+            name='custom_data',
+            field=django.contrib.postgres.fields.hstore.HStoreField(blank=True, null=True),
+        ),
+        migrations.AlterField(
+            model_name='place',
+            name='info_url',
+            field=models.URLField(blank=True, default='', verbose_name='Place home page'),
+        ),
+        migrations.AlterField(
+            model_name='place',
+            name='info_url_en',
+            field=models.URLField(blank=True, default='', null=True, verbose_name='Place home page'),
+        ),
+        migrations.AlterField(
+            model_name='place',
+            name='info_url_fi',
+            field=models.URLField(blank=True, default='', null=True, verbose_name='Place home page'),
+        ),
+        migrations.AlterField(
+            model_name='place',
+            name='info_url_sv',
+            field=models.URLField(blank=True, default='', null=True, verbose_name='Place home page'),
+        ),
+    ]
diff --git a/events/models.py b/events/models.py
--- a/events/models.py
+++ b/events/models.py
@@ -47,7 +47,7 @@ class PublicationStatus:
 
 
 class SchemalessFieldMixin(models.Model):
-    custom_data = HStoreField(null=True)
+    custom_data = HStoreField(null=True, blank=True)
 
     class Meta:
         abstract = True
@@ -125,7 +125,6 @@ def save(self, *args, **kwargs):
         self.last_modified_time = BaseModel.now()
         super(Image, self).save(*args, **kwargs)
 
-
 @python_2_unicode_compatible
 class BaseModel(models.Model):
     id = models.CharField(max_length=50, primary_key=True)
@@ -229,7 +228,7 @@ class KeywordSet(BaseModel):
 
 class Place(MPTTModel, BaseModel, SchemalessFieldMixin):
     publisher = models.ForeignKey(Organization, verbose_name=_('Publisher'), db_index=True)
-    info_url = models.URLField(verbose_name=_('Place home page'), null=True)
+    info_url = models.URLField(verbose_name=_('Place home page'), blank=True, default='')
     description = models.TextField(verbose_name=_('Description'), null=True, blank=True)
     parent = TreeForeignKey('self', null=True, blank=True,
                             related_name='children')


Test patch: