How to create a popup view in Django/Python

Asked

Viewed 297 times

0

Hello, I would like to create a popup to see the detailed information when I click on a link, these data should come from a view and recover data from some attributes of my models.py

kpiMonitoring.html

{% extends 'base.html' %}
    
{% load humanize %}
    
    {% block refresh %}
    <meta http-equiv="refresh" content="240">
    {% endblock refresh %}
    
    {% block title %}
    <title>SMD/PBA - SMD KPI MONITORING</title>
    {% endblock title %}
    
    {% block content %}
    
    <h3>SMD-CE KPI MONITORING</h3>
    
    <h5><input type="button" onclick="window.location.reload()" class="btn btn-dark" style="float:left;" value="REFRESH">
        <button class="btn btn-success" id="copy-table-button" data-clipboard-target="#mytable1"
                style="float:left;">COPY TO EXCEL
        </button>
    
        <a href="" bgcolor="#0080ff" style="float:right; font-weight:bold; color:Red;">Over: {{ timeOverOver }} </a>   
    
         {% if timeOverWaitSAOI > 0 %}
        <a href="" bgcolor="#0080ff" style="float:right; font-weight:bold; color:blue;">SAOI: {{ timeOverWaitSAOI }} &nbsp</a>
        {% else %}
        <a></a>
        {% endif %}
    
         {% if timeOverWaitMAOI > 0 %}
        <a href="" bgcolor="#0080ff" style="float:right; font-weight:bold; color:blue;">MAOI: {{ timeOverWaitMAOI }} &nbsp</a>
        {% else %}
        <a></a>
        {% endif %}
    
        {% if timeOverWaitPAOI > 0 %}
        <a href="" bgcolor="#0080ff" style="float:right; font-weight:bold; color:blue;">PAOI: {{ timeOverWaitPAOI }} &nbsp</a>
        {% else %}
        <a></a>
        {% endif %}
    
        <a style="float:right; color:black;">Time Over + 2hs &nbsp</a>
    </h5>

py views.

from kpi.models import TimeOver
    
def kpiMonitoringView(request):
    
    timeOver = TimeOver.objects.filter(mfg_part_code='P12121', over_status='Time Over')
    timeWait = TimeOver.objects.filter(mfg_part_code='P12121', over_status = 'Wait')
    
    timeOverWait = timeWait.count()
    timeOverWaitPAOI = timeWait.filter(insp_loc ='P').count()
    timeOverWaitMAOI = timeWait.filter(insp_loc='M').count()
    timeOverWaitSAOI = timeWait.filter(insp_loc='S').count()
    
    timeOverOver = timeOver.count()
    
    return render(request,'kpi/kpiMonitoring.html','timeOverWait':timeOverWait, 'timeOverOver':timeOverOver,'timeOverWaitPAOI':timeOverWaitPAOI,'timeOverWaitMAOI':timeOverWaitMAOI, 
    timemeOverWaitSAOI':timeOverWaitSAOI})

py.models

class TimeOver(models.Model):
    work_ymd = models.CharField(max_length=10, blank=True, null=True)
    insp_loc = models.CharField(max_length=10, blank=True, null=True)
    line_nm = models.CharField(max_length=10, blank=True, null=True)
    mfg_part_code = models.CharField(max_length=20, blank=True, null=True)
    bcd_id = models.CharField(max_length=20, blank=True, null=True)
    work_dt = models.CharField(max_length=20, blank=True, null=True)
    over_status = models.CharField(max_length=20, blank=True, null=True)
    
    class Meta:
        managed = False
        db_table = 'time_over'

py.

   from django.urls import path
   from .views import kpiMonitoringView
    
   urlpatterns = [
        path('kpiMonitoringView/',kpiMonitoringView, name="kpiMonitoringView"),
   ]

Therefore, when clicking on the "PAOI" link for example, the page must open a popup to display its following attributes of the models.py: line_nm, bcd_id, work_dt, over_status.

  • Viva, implementa com modal, https://pypi.org/project/django-bootstrap-modal-forms/

  • Thanks Ernesto, I got it done with Bootstrap’s Modal

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.