Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making my first application with Django. The goal is to have a table rendered from my SQlite database that displays the current inventory of laboratory reagents. Once a reagent is taken out of storage a user will be able to hit a subtract button to subtract from the current inventory. Currently I have a table that displays the reagent name and quantity. I would like to add a column to the table that has a subtract button that will subtract one from the corresponding reagents current inventory.

Can anyone please give me some suggestions on how to implement a subtract button? Any help would be much appreciated.

What I have tried:

Python
<pre>models.py

class Reagentquant(models.Model):

    Name_Of_Reagent= models.TextField()
    Reagent_Quantity= models.TextField()

tables.py

class ReagentquantTable(tables.Table):
    class Meta:
        model = Reagentquant
        template_name = 'django_tables2/bootstrap4.html'

views.py

def reagentquant(request):
    table = ReagentquantTable(Reagentquant.objects.all())
    RequestConfig(request).configure(table)
    return render(request, 'inventory/quant.html', {'table': table})

template 

{% load render_table from django_tables2 %}
<!doctype html>
<html>
    <head>
        <title>Inventory Tracker</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
    </head>
    <body>
        {% render_table table %}
    </body>
</html>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900