Django - 'object is not iterable' error but there are no iterations on my object
I have a Model called Request with a Many-To-One model relationship where a User can have multiple Request objects. A Request is a custom made painting Model with many fields.
I am just trying to isolate the specific Request object the User clicked on and show it on a separate template called 'requestcarousel'. I am not running any for loops on the object so I am not sure why I am getting an 'object is not iterable' error. I've tried to use filter instead of get which doesn't give an error but none of the objects are being shown
Here is my view:
def requestcarousel(request, pk=None):
if request.method == 'GET':
allRequests = Request.objects.filter(requested_user=request.user.pk)
requestedPaintings = allRequests.get(pk=pk)
context = {
'requestedPaintings': requestedPaintings,
}
return render(request, "requestcarousel.html", context)
Here is requestcarousel.html:
{% extends "index.html" %}
{% load i18n %}
{% load static %}
{% static "images" as baseUrl %}
{% block request_carousel_content %}
{% get_current_language as LANGUAGE_CODE %}
<!-- START CAROUSEL -->
<div class="card">
<!-- Title -->
<div class="container p-2">
{% if requestedPaintings %}
{% if LANGUAGE_CODE == 'ja' %}
<div class="card-title p-3">
<h4>{{requestedPaintings.name}} </h4>
</div>
{% else %}
<div class="card-title p-3">
<h4>{{requestedPaintings.english_name}} </h4>
</div>
{% endif %}
{% endif %}
</div>
<!-- REQUEST IMAGE UPLOAD START -->
{% if requestedPaintings %}
<div class="owl-carousel owl-theme owl-loaded" id="myCarousel" style=" margin: 0 auto !important;">
{% if requestedPaintings.painting %}
<div class="item">
<div class="slide-content">
<img src="{{requestedPaintings.painting.url}}" />
</div>
</div>
{% else %}
<!-- skip it -->
{% endif %}
</div>
{% endif %}
<!-- add dimensions to painting -->
<div class="container p-2">
{% if requestedPaintings %}
<div class="painting_description gallery-item text-center">
{% if LANGUAGE_CODE == 'ja' %}
<p class="text-center" id="carousel_long_desc" style="font-family: 'Oswald', sans-serif !important;">{{requestedPaintings.cm_size}} (センチ) <br> {{requestedPaintings.in_size}}(インチ) </p>
<p id="carousel_long_desc" >{{requestedPaintings.long_description}} </p>
{% else %}
<p class="text-center" id="carousel_long_desc" style="font-family: 'Oswald', sans-serif !important;">{{requestedPaintings.cm_size}} (cm) <br> {{requestedPaintings.in_size}} (in)</p>
<p id="carousel_long_desc" >{{requestedPaintings.english_long_description}} </p>
{% endif %}
</div>
{% endif %}
<div class="text-end">
<!-- START REQUEST SOLD LABEL, PRICE DISPLAY, BUY BUTTON -->
{% if requestedPaintings.is_sold is True %}
<div class="container">
<p class="p-1 mt-1 fw-bold text-light rounded"style="background-color: rgb(255, 73, 73); font-size:small; float: right;">SOLD</p>
</div>
{% else %}
<!-- yen or dollar display-->
<div class="card-text">
{% if request.user.account.country == 'JP' %}
<div class="jpy_currency" id="jpy-price-{{requestedPaintings.pk}}">
¥{{requestedPaintings.price}}<p id="carousel_long_desc">({% trans 'スタンド付き' %})</p>
</div>
{% else %}
<!-- initially show jpy -->
<div class="usd_currency" id="usd-price-{{requestedPaintings.pk}}">
${{requestedPaintings.dollar_price}}<p id="carousel_long_desc">({% trans 'スタンド付き' %})</p>
</div>
{% endif %}
</div>
{% endif %}
{% if requestedPaintings.final_request is True %}
<a class="btn btn-sm btn-outline-info text-dark"
href="/../{{LANGUAGE_CODE}}/checkout/{{requestedPaintings.id}}">
{% trans '購入する' %}
</a>
{% else %}
{% endif %}
</div>
</div>
</div>
{% endblock %}