How to display results if number of units are less than 2 using Djang and Python

59
November 16, 2019, at 6:50 PM

I have created a model named Product containing these fields ('prod_name', 'company', 'quantity', 'price', 'units', 'prod_type')

I want to display those products in the webpage that have less than 2 units remaining

this is what I have tried:

Here is my views.py file:

from django.shortcuts import render, redirect, get_object_or_404
from django.views.generic import TemplateView, ListView
from django.db.models import Q
from .models import *
from .forms import *
def get_stock(request):
   items=Product.objects.filter(units__lte=2)
   context={
     'items':items
    }
   return render(request, 'UpdateStock.html', context)

here is my urls file:

from django.conf.urls import url
from django.urls import path
from .views import *
urlpatterns=[
   url(r'^get_stock$', get_stock, name='get_stock'),
]

here is my HTML file for the same

{% extends 'base.html' %}
    {% block body %}
    <br>
        <h3>Update Stocks</h3>
    <br>
    <table class="table table-hover">
        <thead>
            <tr>
                <th>Sr. No.</th>
                <th>Product Name</th>
                <th>Company</th>
                <th>Quantity</th>
                <th>Price</th>
                <th>Units</th>
                <th>Product Type</th>
            </tr>
        </thead>
        <tbody>
            {% for item in object_list %}
            <tr>
                <td>{{item.pk}}</td>
                <td>{{item.prod_name}}</td>
                <td>{{item.company}}</td>
                <td>{{item.quantity}}</td>
                <td>{{item.price}}</td>
                <td>{{item.units}}</td>
                <td>{{item.prod_type}}</td>
            </tr>

            {% endfor %}
        </tbody>
    </table>    
    {% endblock %}

But the results are not getting displayed

READ ALSO
How to implement inbox only to read data from firebase database

How to implement inbox only to read data from firebase database

I want to implement a inbox where a user only can read the text from other userI designed my firebase database structure

51
How to align element at the bottom of screen using CSS?

How to align element at the bottom of screen using CSS?

How do I align an element at the bottom of a window (independent of the screen size), BUT it remains in that position such that when the window height is reduced (when a user alters window size) it remains in that exact location and is out of view in the window...

71
controller does not receive data from ajax

controller does not receive data from ajax

well in my learning ofnet core with mvc template I have a challenge and it is to send an image and data of some herlpers to a cotrolator with ajax he tried several ways already but I always find the error that neither my object model is null and in the HttpContext

62
How to update the foreign key value of table 2 from the primary key of table 1

How to update the foreign key value of table 2 from the primary key of table 1

Currently, I have 2 tables which table 1 has the primary key of customer_id and table 2 has the foreign key of customer_idMy issue is, I tried to update the value of the foreign key from the value of primary key, but the value is always 0 for foreign...

61