[Answer]-Check remembered radio button selection in for loop

1👍

Based on your answer:

  1. You’re setting the value of picked_id from the request.POST dict in your view.
  2. All values in request.POST are, by default, strings.
  3. The object_list is probably a list from the ORM.
  4. Which means the element.id is a PK field.
  5. Which is gonna be an int.

So you need to cast ‘picked_id’ into an int before you save it to the session.

So:

request.session['picked_id'] = int(request.POST.get('object', 0))

… or however you’re doing it in your view.

Leave a comment