0

Here are the docs. I need help kicking in the id parameter under the change function, so that it reroutes the url to the correct admin edit page.

In a very similar question, the following answer was listed:

{% url 'admin:polls_choice_change' choice.id %}

Did I wrap in {% for %} tags correctly? Am I supposed to?

my views.py:

def customer_details(request, id):
    var = model.objects.get(id=id)
    return render(request, 'vendor_db/vendors_detail.html', {'var': var,
    })

customer_details.html:

{% for items in var %}
   <a href="{% url 'admin:app_model_change' items.id %}">Edit</a>
{% endfor %}

UPDATE

question was answered in comments, thanks for the help!

Community
  • 1
  • 1
Kervvv
  • 751
  • 4
  • 14
  • 27
  • 3
    when you do `model.objects.get()` it returns a single instance not a list, if you do `model.objects.filter()` then you can do a `for loop`, just get rid of the `for loop` and use the `var.id` – abhishekgarg May 02 '16 at 20:08
  • 1
    But why do you want a for loop at all? – Daniel Roseman May 02 '16 at 20:19
  • And of course `app` and `model` should be replaced with the name of your app and model. – Dan Russell May 02 '16 at 20:20
  • @abhishekgarg You are right, it worked! All I needed was write was var.id in the template. Thanks a million! – Kervvv May 03 '16 at 12:52
  • @DanielRoseman The `for` loop was not needed, I thought I would have to wrap it in some sort of `{% %}` tag but it was already wrapped in `{% url ' ' %}` . Thank you for the insight! – Kervvv May 03 '16 at 12:56

0 Answers0