SHARE
TWEET

Untitled

a guest Jul 24th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.contrib.gis.db import models as geomodels
  2. from django.db import models
  3.  
  4. class AddPoint(models.Model):
  5.     name = models.CharField(max_length=100)
  6.     point = geomodels.PointField()
  7.  
  8.     def __str__(self):
  9.         return self.name
  10.      
  11. from django import forms
  12. from django.contrib.gis import forms
  13.  
  14. class AddPointForm(forms.ModelForm):
  15.     name = forms.CharField(
  16.         max_length=100,
  17.         widget=forms.TextInput(
  18.             attrs={
  19.                 "type": "text",
  20.                 "class": "form-control form-control-lg",
  21.                 }
  22.             ),
  23.         )
  24.     point = forms.PointField(
  25.         widget=forms.OSMWidget(
  26.             attrs={
  27.                 'map_width': 800,
  28.                 'map_height': 500,
  29.                 }
  30.             ),
  31.         )
  32.  
  33.     class Meta:
  34.         model = AddPoint
  35.         fields = []
  36.      
  37. def addPointOnMap(request):
  38.     if request.method == "POST":
  39.         geoform = AddPointForm(request.POST or None)
  40.         if geoform.is_valid():
  41.             new_point = geoform.save()
  42.             new_point.save()
  43.             return redirect('add_points_map')
  44.     else:
  45.         geoform = AddPointForm()
  46.     context = {
  47.         'geoform': geoform,
  48.         }
  49.     template = 'maps/editing/add_point.html'
  50.     return render(request, template, context)
  51.      
  52. <form method="POST" enctype="multipart/form-data" novalidate>{% csrf_token %}
  53.     {{ geoform.as_p }}
  54.     <hr>
  55.     <div class="row justify-content-md-center">
  56.       <div class="col-md-auto">
  57.         <input type="submit" class="btn btn-info shadow" value="SHARE">
  58.       </div>
  59.     </div>
  60.   </form>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top