I'm making my portfolio site. Each project is developed with multiple technologies, such as a "website" created with Python, Django and Bootstrap.
So I defined my models like this:
class Technology(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Meta:
verbose_name_plural = 'Technologies'
class Project(models.Model):
name = models.CharField(max_length=200)
description = models.TextField()
date = models.DateField()
technology = models.ManyToManyField(Technology)
image = models.ImageField(upload_to='projects')
def __str__(self):
return self.name
views.py:
def index(request):
projects = Project.objects.all()
return render(request, 'homepage/index.html', context={'projects': projects})
Now here's the challenge:
In my template I want to display 6 projects with the project name and technologies extracted from the '''queryobject'''. However right now I have only one project. So:
- How to display one set of HTML tags for first project and another set (placeholders) for the rest? So the first project shows the data from database, and the rest 5 show a "coming soon" (please refer to attached screenshot)? And later when I add the second and third projects to the database, the output update itself accordingly?
- Since the "technology" field is a
manytomany
field, there is more than one value in it (Python, Django, Bootstrap for example). How to access it in my template?
EDIT:
I feel I need to explain a little more. What I need for each project I have:
- Project Name
- First technology
- All technologies - This is needed for a javascript library I use to filter out projects based on technology. It looks like this:
<div class="col-lg-4 col-md-6 portfolio-item filter-python filter-django filter-bootstrap">