Implementing a map within a form

26 views
Skip to first unread message

Ziyad Alshaikh

unread,
Feb 16, 2021, 8:58:45 AM2/16/21
to Django users
Hi, 
I'm currently trying to implement a map within a form using class based model.
The map does not show on the page/form. The map, however, shows on the admin page
and stores the location successfully.

Any thoughts on where is the problem?

Model
from django.contrib.gis.db import models

class Property(models.Model):
....
location = models.PointField()
....

View

class PropertyCreate(CreateView):
form_class = PropertyForm
model = Property
.....

Forms
class PropertyForm(forms.ModelForm):

location = forms.PointField(widget=
forms.OSMWidget(attrs={'map_width': 800, 'map_height': 500}))

class Meta:
model = Property

Template

<form action="" method="post">
<div class="row">
<div class="col-md-8"> {{form.location }}</div>
</div>

Reply all
Reply to author
Forward
0 new messages