Answer the question
In order to leave comments, you need to log in
How to write data to json when object is created?
There is a model:
class School(models.Model):
slug = models.SlugField(unique=True, verbose_name='ЧПУ')
title = models.CharField(max_length=300, verbose_name='Название')
adress = models.CharField(max_length=300, verbose_name='Адрес')
def __unicode__(self):
return u'%s' % (self.title)
def mygeo(self):
g = geocoder.google(self.adress)
return g.latlng
{
"type": "FeatureCollection",
"features": [
{"type": "Feature", "id": 0, "geometry": {"type": "Point", "coordinates": [55.831903, 37.411961]}, "properties": {"balloonContentHeader": "<font size=3><b><a target='_blank' href='https://yandex.ru'>Здесь может быть ваша ссылка</a></b></font>"}}
]
}
{
"type": "FeatureCollection",
"features": [
{"type": "Feature", "id": "{{school.id}}", "geometry": {"type": "Point", "coordinates": {{school.mygeo}}}, "properties": {"balloonContentHeader": "<font size=3><b><a target='_blank' href='/school/{{school.slug}}'>{{school.title}}</a></b></font>"}}
]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question