how to pass the value of list indjango to method

  django, html, jinja2, python, scripting

I am trying to do something like this, I have a navigation bar with li items.

**index.html**
<ul class="submenu dropdown-menu">
 <li><a class="dropdown-item" name="mis" href="{% url 'pdfNotes'%}">MIS</a></li>
                          <li><a class="dropdown-item" href="{% url 'pdfNotes'%}">MA</a></li>
                          <li><a class="dropdown-item" href="{% url 'pdfNotes'%}">UXD</a></li>
                          <li><a class="dropdown-item" href="{% url 'pdfNotes'%}">OSS</a></li>
</ul>

here when I navigate to the first list ‘

  • ‘ i.e for MIS I have to redirect to pdfNotes.html with the name as ‘mis’ so that I can use this as a parameter in views.py to filter my data and display only ‘MIS’ details in pdf notes. same for all other li items.

    **pdfNotes.html**
    {% if pdfnote %}
    
    
    <table>
    
        <tr>
            <th># </th>
            <th>NAME</th>
            <th>DOWNLOAD FILE</th>
        </tr>
        {% with counter=1 %}
        {% for item in pdfnote %} 
        {% with crs=item.course %}
        
        <tr>
            <td id="id">{{crs}}</td>
            <td id="id">{{pattn}}</td>
            <td id="id">{{sem}}</td>
            <td id="id">{{ forloop.counter}}</td>
            <td id="name">{{item.name}}</td>
            <td id="downloadBtn">
                <a href="{{item.file.url}}" class="btn-outline-success" download >DOWNLOAD</a>
            </td>    
        </tr>
        {% endwith %}
        {% endfor %}
        {% endwith %}
    </table>
    
    
    **model.pdf**
    
    class PDF_Notes(models.Model):
    
        name=models.CharField("File name",max_length=100)
        subject=models.CharField("Subject",max_length=50)
        course=models.CharField("Course",max_length=50)
        semester=models.CharField("Semister",max_length=50)
        year=models.CharField("Year",max_length=50)
        source=models.CharField("Source",max_length=100)
        file=models.FileField(upload_to="media/PdfNotes")
    
        def __str__(self):
            return self.name
    
    
    **view.py**
    
    def pdfNotes(request):
    
        pdfNotes_file=PDF_Notes.objects.all()
        #sub=request.GET[]
        if(request.GET['mis']):
            pdfNotes_file=PDF_Notes.objects.all().filter(subject="MIS")
        n=len(pdfNotes_file)
        print("hello",pdfNotes_file)
        params={'pdfnote':pdfNotes_file,'total_items':n}
        return render(request,'pdfNotes.html',params)
    

    how can I do that, please… Thanx!!

    Source: Python Questions

  • LEAVE A COMMENT