Am trying to just get a list of the made up gigs, (and hopefully make them links, to view them in a different html).
Page result right now looks like this;
<QuerySet [<Gig: Fulltime assistent needed from fall 2021!>, <Gig: Looking for event staff!>]>
I don’t know how to remove queryset ‘code markers(or what are they called?)’. Just want the gig names listed. How can I fix that, to just show the gig titles?
This is my code:
Html:
JavaScript
x
16
16
1
<div class="col">
2
{% if profile %}
3
<div class="row justify-content-between">
4
<div class="col-9">
5
<p><b>My Gigs:</b></p>
6
<p>{{profile.my_gigs}}</p>
7
</div>
8
<div class="col-3">
9
<p class="text-center"><b>No:</b></p>
10
<p class="text-center"> {{profile.num_gigs}}</p>
11
</div>
12
<br>
13
</div>
14
{% endif %}
15
</div>
16
Views:
JavaScript
1
16
16
1
def my_gigs(request):
2
profile = Profileuser.objects.get(user=request.user)
3
template = 'profileusers/my_gigs.html'
4
context = {
5
'profile': profile,
6
}
7
return render(request, template, context)
8
9
def create_gig(request):
10
profile = Profileuser.objects.get(user=request.user)
11
template = 'profileusers/create_gig.html'
12
context = {
13
'profile': profile,
14
}
15
return render(request, template, context)
16
Model:
JavaScript
1
8
1
def my_gigs(self):
2
return self.gig_set.all()
3
4
@property
5
def num_gigs(self):
6
# pylint: disable=maybe-no-member
7
return self.gig_set.all().count()
8
Advertisement
Answer
You iterate over the gigs
, so:
JavaScript
1
1
1
<p>{% for gig in profile.my_gigs %}{{ gig }} {% endfor %}</p>
In that case it will thus make a query, and enumerate over the Gig
s wrapped in the queryset. Each gig
is then rendered individually.