Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position working admin but not in forms #76

Open
sambanks opened this issue Sep 25, 2016 · 1 comment
Open

Position working admin but not in forms #76

sambanks opened this issue Sep 25, 2016 · 1 comment

Comments

@sambanks
Copy link

sambanks commented Sep 25, 2016

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

@zelds
Copy link

zelds commented Jan 8, 2017

have the same trouble request.POST.get('position') dosen`t help.
Maybe u have answer ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants