Notes:
i have Project Model and Image Model With Foreign Key for Project Model.
i have HTML Page With All Projects i got all data of Each Project Only Image Can Not get it.
it suppose to popup Carousel with images for Each Project when i Click on button,
Carousel is working and Ready, Only Images Can Not Access.
Any Clue To Follow Please. Thanks In Advance.
HTML NavBar:
<a class="item" href="{% url 'pages:all_projects' %}">Projects</a>
HTML Project Page:
<div class="ui four columns grid">
{% for project in projects %}
<div class="column">
<div class="ui cards">
<div class="ui green raised segment">
<div class="ui fluid card">
<div class="image">
<img src="{{ project.image_set.first.url }}" class="ui fluid image"/>
</div>
<div class="content">
<div class="header">{{ project.name }}</div>
<div class="meta">{{ project.area }}</div>
<div class="ui raised green segment">
<div class="ui botton" onclick="project_images_modal()">View More</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui modal Project_Modal">
<div class="ui three column grid container">
<div class="one wide column">
<button id="Project_Image_Flipper_Left" class="ui center icon button" onclick="flip_me_left()">
<i class="angle double left icon"></i>
</button>
</div>
<div class="fourteen wide column">
<div class="ui cube shape">
<div class="sides">
<div class="active side">
<div class="content">
<div class="center">
<img src="{{ project.image_set.first.url }}"
class="ui rounded massive image"/>
</div>
</div>
</div>
{% for project_image in project_images %}
<div class="side">
<div class="content">
<div class="center">
<img src="{{ project.image.url }}"
class="ui rounded massive image"/>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
<div class="one wide column">
<button id="Project_Image_Flipper_Right" class="ui icon button" onclick="flip_me_right()">
<i class="angle double right icon"></i>
</button>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
Models:
class Project(models.Model):
name = models.CharField(verbose_name='Name', max_length=255)
area = models.CharField(verbose_name='Area', max_length=255)
year = models.CharField(verbose_name='Date-Time', max_length=255)
slug = models.SlugField(verbose_name='Slug', unique=True)
class Meta:
ordering = ['area', '-year', 'name']
def get_absolute_url(self):
return reverse('pages:all_projects', kwargs={'slug': self.slug})
def __str__(self):
return f'{self.name} - {self.area}'
class Image(models.Model):
project = models.ForeignKey('Project', verbose_name='Project', on_delete=models.CASCADE)
image = models.ImageField(verbose_name='Image', default=default_image, upload_to=upload_project_image)
class Meta:
verbose_name_plural = 'Images'
def __str__(self):
return f'{self.project.name}'
Views:
def all_projects(request):
projects = Project.objects.all()
images = Image.objects.all()
page = 'Projects'
context = {
'page': page,
'projects': projects,
'images': images,
}
return render(request, 'pages/projects.html', context)
Urls:
path('projects', views.all_projects, name='all_projects'),