It's not working.
class PetOwnerDetailView(DetailView):
model = PetOwner
context_object_name = "owner"
template_name = "pet_owner_profile.html"
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(**kwargs)
context['pet_photos'] = {}
pets = PetOwner.objects.filter(name = "pets")
for pet in pets:
context['pet_photos'][pet] = []
for photo in pet.pet_photos:
context['pet_photos'][pet] += photo
# context['pet_photos'] = {pet1: [photo1, photo2, photo3], pet2:
[photo1, photo2]}
return context
{% extends "base.html" %}
{% block header %}
{% endblock %}
{% block content %}
{{ owner.name }}
{{ owner.age }}
{{ owner.location }}
{{ owner.profile_photo }}
{% for pet in owner.pets.all %}
{{ pet.name }}
{{ pet.animaltype }}
{{ pet.age }}
<!-- context['pet_photos'] = {pet1: [photo1, photo2, photo3], pet2:
[photo1, photo2]} -->
{% for photo in pet_photos.pet.photos %}
<img src = "{{ photo.photo.url }}">
{% endfor %}
{% endfor %}
{% endblock %}
Nothing shows up. I've tried a million and a half ways to iterate over the
data structure I've created to store pets as keys and photos in a list as
values in get_context_data for 'pet_photos' but nothing ever displays.
Then there's the question of like, are my directory structure and settings
file correct.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
pet_memorial/static/ is the file path. I don't know if that's right or it
needs to be in the project sub-directory. It's impossible to figure this
out online. No one explains these simple simple things CLEARLY.
So frustrating.
Michael
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/df428834-55c9-4657-b734-e300d55929fdn%40googlegroups.com.