You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use geoposition to add a simple google maps input to a form, but am a bit stuck. I have added the model and the widget works in the admin console. However when I add it to a form it doesn't populate the position field. I would really appreciate if anyone could show me where I'm going wrong.
My code is:
Hi There
I am trying to use geoposition to add a simple google maps input to a form, but am a bit stuck. I have added the model and the widget works in the admin console. However when I add it to a form it doesn't populate the position field. I would really appreciate if anyone could show me where I'm going wrong.
My code is:
models.py
class Review(models.Model):
RATING_CHOICES = (
(1, '1'),
(2, '2'),
(3, '3'),
(4, '4'),
(5, '5'),
)
thing = models.ForeignKey(Thing)
pub_date = models.DateTimeField('date published')
user_name = models.CharField(max_length=100)
comment = models.CharField(max_length=100)
rating = models.IntegerField(choices=RATING_CHOICES)
photo = models.ImageField(upload_to='review_images',default=None, blank=True, null=True)
tag = models.CharField(max_length=100)
position = GeopositionField()
views.py:
def add_review(request, slug):
thing = get_object_or_404(Thing, slug=slug)
form = ReviewForm(request.POST)
if form.is_valid():
rating = form.cleaned_data['rating']
comment = form.cleaned_data['comment']
photo = form.cleaned_data['photo']
position = form.cleaned_data['position']
user_name = request.user.username
review = Review()
review.thing = thing
review.postion = position
review.user_name = user_name
review.rating = rating
review.comment = comment
review.photo = photo
review.pub_date = datetime.datetime.now()
review.tag = slugify(user_name) + '-' + slugify(thing)
review.save()
return HttpResponseRedirect(reverse('reviews:thing_detail', args=(thing.slug,)))
return render(request, 'reviews/thing_detail.html', {'thing': thing, 'form': form})
Any idea where I'm going wrong?
Cheers
Sam
The text was updated successfully, but these errors were encountered: