Add a migration to create a TileLayer if none exists

This commit is contained in:
Yohan Boniface 2016-11-26 17:25:59 +01:00
parent 197682c691
commit 3c32377c42
3 changed files with 29 additions and 11 deletions

View file

@ -104,17 +104,6 @@ For example:
- name: `ODbL` - name: `ODbL`
- URL: `http://opendatacommons.org/licenses/odbl/` - URL: `http://opendatacommons.org/licenses/odbl/`
## Add at least one tilelayer
Go to [http://localhost:8000/admin/leaflet_storage/tilelayer/add/](http://localhost:8000/admin/leaflet_storage/tilelayer/add/) and create
a new TileLayer object.
For example:
- name: `Positron`
- URL template: `https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png`
- attribution: `© [[http://www.openstreetmap.org/copyright|OpenStreetMap]] contributors, © [[https://carto.com/attributions|CARTO]]`
You can now go to [http://localhost:8000/](http://localhost:8000/) and try to create a map for testing. You can now go to [http://localhost:8000/](http://localhost:8000/) and try to create a map for testing.
When you're done with testing, quit the demo server (type Ctrl-C). When you're done with testing, quit the demo server (type Ctrl-C).

View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-11-26 16:02
from __future__ import unicode_literals
from django.db import migrations
def add_tilelayer(apps, *args):
TileLayer = apps.get_model('leaflet_storage', 'TileLayer')
if TileLayer.objects.count():
return
TileLayer(
name='Positron',
url_template=('https://cartodb-basemaps-{s}.global.ssl.fastly.net/'
'light_all/{z}/{x}/{y}.png'),
attribution=('© [[http://www.openstreetmap.org/copyright|'
'OpenStreetMap]] contributors, © '
'[[https://carto.com/attributions|CARTO]]')).save()
class Migration(migrations.Migration):
dependencies = [
('leaflet_storage', '0001_initial'),
]
operations = [
migrations.RunPython(add_tilelayer),
]

View file