Skip to content
Advertisement

How to remove the querysets ‘< [ (code markers?)’ for html (Django)

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:

                <div class="col">
                    {% if profile %}
                    <div class="row justify-content-between">
                        <div class="col-9">
                            <p><b>My Gigs:</b></p>
                            <p>{{profile.my_gigs}}</p>
                        </div>
                        <div class="col-3">
                            <p class="text-center"><b>No:</b></p>
                            <p class="text-center"> {{profile.num_gigs}}</p>
                        </div>
                        <br>
                    </div>
                    {% endif %}
                </div>

Views:

def my_gigs(request):
    profile = Profileuser.objects.get(user=request.user)
    template = 'profileusers/my_gigs.html'
    context = {
        'profile': profile,
    }
    return render(request, template, context)

def create_gig(request):
    profile = Profileuser.objects.get(user=request.user)
    template = 'profileusers/create_gig.html'
    context = {
        'profile': profile,
    }
    return render(request, template, context)

Model:

def my_gigs(self):
    return self.gig_set.all()

@property
def num_gigs(self):
    # pylint: disable=maybe-no-member
    return self.gig_set.all().count() 

Advertisement

Answer

You iterate over the gigs, so:

<p>{% for gig in profile.my_gigs %}{{ gig }} {% endfor %}</p>

In that case it will thus make a query, and enumerate over the Gigs wrapped in the queryset. Each gig is then rendered individually.

Advertisement