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:
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:
<div class="col-lg-4 col-md-6 portfolio-item filter-python filter-django filter-bootstrap">
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:
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:
<div class="col-lg-4 col-md-6 portfolio-item filter-python filter-django filter-bootstrap">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.