<<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Gallery</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e2808d8d969196908392a2d7cd0ccd3">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
<style>
.image-thumbnail {
height: 200px;
object-fit: cover;
}
.container {
margin-left: 1;
}
.h1 {
text-align: center;
}
.list-group-item a {
text-decoration: none;
color: black;
}
</style>
</head>
<h1 class="text-center m-5 p-3 mb-2 bg-light text-secondary">CHARLIES LIFE</h1>
<body class="m-5">
<div class="container">
<div class="row">
<div class="col-md-3 mt-2">
<div class="card">
<div class="card-header">
Categories
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<a href="{% url 'gallery' %}">All</a>
</li>
{% for category in categories %}
<li class="list-group-item">
<a href="{% url 'gallery' %}?category={{category.name}}">{{category.name}}
</a>
</li>
{% endfor %}
<a href="{% url 'add' %}" class="btn btn-dark btn-block m-1" type="button""> Add Photo</a>
</ul>
</div>
</div>
<div class=" col-md-9">
<div class="row">
{% for photo in photos %}
<div class="col-md-4">
<div class="card my-2">
<img class="image-thumbnail" src="{{photo.image.url}}" class="card-img-cap"
alt="...">
<div class="card-body">
<p class="card-text text-center">{{photo.category.name}}</p>
</div>
<div class="d-grid gap-2">
<a href="{% url 'photo' photo.id %}" class="btn btn-dark m-1"
type="button"> View</a>
</div>
</div>
</div>
{% empty %}
<h3> No Photos...</h3>
{% endfor %}
</body>
</html>
Hi, I'm currently building a photo blog to document the journey of my son as he grows. The code above represents the "home" page named gallery.
Currently, I have a loop that adds a "card" class to my gallery page each time I upload an image.
I would like to modify it so that it displays only one picture from each category I create, rather than showing every image uploaded to the site. I didn't anticipate the number of photos I would upload, and I don't want the home page to become overloaded with images.
If anyone has any suggestions on how I can achieve this or any other recommendations, I would greatly appreciate it.
Thank you in advance.