Why can I only populate 1 row in webpage with Django framework?

This is now driving me crazy. I used to get only the last row, whatever it was, but now I only get a specific row {{ item.Basil_qty_futurecol, which happens to be the last, and nothing else. I cannot see what is different from the rest of the tables that makes it and only it work. I've gone over it with a fine toothed comb and found nothing wrong. I just know it will be totally obvious once it's pointed out to me.

The UI with only Next Order Basil Qty rendered

The code

Settings.py

"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 3.1.4.

"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
print(BASE_DIR)

# Quick-start development settings - unsuitable for production

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#####################################################'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'

# Application definition

INSTALLED_APPS = [
    'myapi.apps.MyapiConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'expeditor',
        'USER': 'Paul',
        'PASSWORD': '##########',
        'HOST': 'localhost',
        'PORT': '3306',
        
    }
}


# Password validation

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'

STATICFILES_DIR = [
    os.path.join(BASE_DIR, 'static'),
]

#STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Models.py

from django.db import models

# Create your models here.

class romaine_qty_past(models.Model):
    idRomaine_order_past = models.AutoField(db_column='idRomaine_order_past', primary_key=True)  # Field name made lowercase.
    Romaine_qty_pastcol = models.IntegerField(blank=True, null=True)

class romaine_qty(models.Model):
    idRomaine_order = models.AutoField(db_column='idRomaine_order', primary_key=True)  # Field name made lowercase.
    Romaine_qtycol = models.IntegerField(blank=True, null=True)
    
class romaine_qty_future(models.Model):
    idRomaine_order_future = models.AutoField(db_column='idRomaine_order_future', primary_key=True)  # Field name made lowercase.
    Romaine_qty_futurecol = models.IntegerField(blank=True, null=True)
    
class Meta:
    #managed = true
    db_table = 'romaine_qty_past'
    
class Meta:
    #managed = true
    db_table = 'romaine_qty'
    
class Meta:
    #managed = true
    db_table = 'romaine_qty_future'
    
class kale_qty_past(models.Model):
    idKale_order_past = models.AutoField(db_column='idKale_order_past', primary_key=True)  # Field name made lowercase.
    Kale_qty_pastcol = models.IntegerField(blank=True, null=True)

class kale_qty(models.Model):
    idKale_order = models.AutoField(db_column='idKale_order', primary_key=True)  # Field name made lowercase.
    Kale_qtycol = models.IntegerField(blank=True, null=True)
    
class kale_qty_future(models.Model):
    idKale_order_future = models.AutoField(db_column='idKale_order_future', primary_key=True)  # Field name made lowercase.
    Kale_qty_futurecol = models.IntegerField(blank=True, null=True)
    
class Meta:
    #managed = true
    db_table = 'kale_qty_past'
    
class Meta:
    #managed = true
    db_table = 'kale_qty'
    
class Meta:
    #managed = true
    db_table = 'kale_qty_future'
    
class basil_qty_past(models.Model):
    idBasil_order_past = models.AutoField(db_column='idBasil_order_past', primary_key=True)  # Field name made lowercase.
    Basil_qty_pastcol = models.IntegerField(blank=True, null=True)

class basil_qty(models.Model):
    idBasil_order = models.AutoField(db_column='idBasil_order', primary_key=True)  # Field name made lowercase.
    Basil_qtycol = models.IntegerField(blank=True, null=True)
    
class basil_qty_future(models.Model):
    idBasil_order_future = models.AutoField(db_column='idBasil_order_future', primary_key=True)  # Field name made lowercase.
    Basil_qty_futurecol = models.IntegerField(blank=True, null=True)
    
class Meta:
    #managed = true
    db_table = 'basil_qty_past'
    
class Meta:
    #managed = true
    db_table = 'basil_qty'
    
class Meta:
    #managed = true
    db_table = 'basil_qty_future'
    
def __str__(self):
    return self.name

admin.py

from django.contrib import admin

# Register your models here.

from .models import romaine_qty_past
from .models import romaine_qty
from .models import romaine_qty_future

admin.site.register(romaine_qty_past)
admin.site.register(romaine_qty)
admin.site.register(romaine_qty_future)

from .models import kale_qty_past
from .models import kale_qty
from .models import kale_qty_future

admin.site.register(kale_qty_past)
admin.site.register(kale_qty)
admin.site.register(kale_qty_future)

from .models import basil_qty_past
from .models import basil_qty
from .models import basil_qty_future

admin.site.register(basil_qty_past)
admin.site.register(basil_qty)
admin.site.register(basil_qty_future)

serializers.py

# serializers.py

from rest_framework import serializers

from .models import romaine_qty_past
from .models import romaine_qty
from .models import romaine_qty_future

class romaine_qty_pastSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = romaine_qty_past
        fields = ('idRomaine_order_past', 'Romaine_qty_pastcol')

class romaine_qtySerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = romaine_qty
        fields = ('idRomaine_order', 'Romaine_qtycol')
        
class romaine_qty_futureSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = romaine_qty_future
        fields = ('idRomaine_order_future', 'Romaine_qty_futurecol')
        
from .models import kale_qty_past
from .models import kale_qty
from .models import kale_qty_future

class kale_qty_pastSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = kale_qty_past
        fields = ('idKale_order_past', 'Kale_qty_pastcol')

class kale_qtySerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = kale_qty
        fields = ('idKale_order', 'Kale_qtycol')
        
class kale_qty_futureSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = kale_qty_future
        fields = ('idKale_order_future', 'Kale_qty_futurecol')
        
from .models import basil_qty_past
from .models import basil_qty
from .models import basil_qty_future

class basil_qty_pastSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = basil_qty_past
        fields = ('idBasil_order_past', 'Basil_qty_pastcol')

class basil_qtySerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = basil_qty
        fields = ('idBasil_order', 'Basil_qtycol')
        
class basil_qty_futureSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = basil_qty_future
        fields = ('idBasil_order_future', 'Basil_qty_futurecol')

views.py

#views.py

from django.http import HttpResponse
from django.shortcuts import render
from django.template.context import RequestContext

# Create your views here.

from rest_framework import viewsets

from .serializers import romaine_qty_pastSerializer
from .serializers import romaine_qtySerializer
from .serializers import romaine_qty_futureSerializer
from .models import romaine_qty_past
from .models import romaine_qty
from .models import romaine_qty_future

def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = romaine_qty_past.objects.all()
    return render(request, "index.html", {'query_results':query_results})

def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = romaine_qty.objects.all()
    return render(request, "index.html", {'query_results':query_results})
    
def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = romaine_qty_future.objects.all()
    return render(request, "index.html", {'query_results':query_results})
    
def index(request):
    return render("index.html", context_instance=RequestContext(request))
    
class romaine_qty_pastViewSet(viewsets.ModelViewSet):
    queryset = romaine_qty_past.objects.all().order_by('idRomaine_order_past', 'Romaine_qty_pastcol')
    serializer_class = romaine_qty_pastSerializer
    
class romaine_qtyViewSet(viewsets.ModelViewSet):
    queryset = romaine_qty.objects.all().order_by('idRomaine_order', 'Romaine_qtycol')
    serializer_class = romaine_qtySerializer

class romaine_qty_futureViewSet(viewsets.ModelViewSet):
    queryset = romaine_qty_future.objects.all().order_by('idRomaine_order_future', 'Romaine_qty_futurecol')
    serializer_class = romaine_qty_futureSerializer
    
from .serializers import kale_qty_pastSerializer
from .serializers import kale_qtySerializer
from .serializers import kale_qty_futureSerializer
from .models import kale_qty_past
from .models import kale_qty
from .models import kale_qty_future

def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = kale_qty_past.objects.all()
    return render(request, "index.html", {'query_results':query_results})

def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = kale_qty.objects.all()
    return render(request, "index.html", {'query_results':query_results})
    
def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = kale_qty_future.objects.all()
    return render(request, "index.html", {'query_results':query_results})
    
def index(request):
    return render("index.html", context_instance=RequestContext(request))
    
class kale_qty_pastViewSet(viewsets.ModelViewSet):
    queryset = kale_qty_past.objects.all().order_by('idKale_order_past', 'Kale_qty_pastcol')
    serializer_class = kale_qty_pastSerializer
    
class kale_qtyViewSet(viewsets.ModelViewSet):
    queryset = kale_qty.objects.all().order_by('idKale_order', 'Kale_qtycol')
    serializer_class = kale_qtySerializer

class kale_qty_futureViewSet(viewsets.ModelViewSet):
    queryset = kale_qty_future.objects.all().order_by('idKale_order_future', 'Kale_qty_futurecol')
    serializer_class = kale_qty_futureSerializer
    
from .serializers import basil_qty_pastSerializer
from .serializers import basil_qtySerializer
from .serializers import basil_qty_futureSerializer
from .models import basil_qty_past
from .models import basil_qty
from .models import basil_qty_future

def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = basil_qty_past.objects.all()
    return render(request, "index.html", {'query_results':query_results})

def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = basil_qty.objects.all()
    return render(request, "index.html", {'query_results':query_results})
    
def UI_Supermarket_Restaurant(request, *args, **kwargs):
    print(args, kwargs)
    print(request.user)
    query_results = basil_qty_future.objects.all()
    return render(request, "index.html", {'query_results':query_results})
    
def index(request):
    return render("index.html", context_instance=RequestContext(request))
    
class basil_qty_pastViewSet(viewsets.ModelViewSet):
    queryset = basil_qty_past.objects.all().order_by('idBasil_order_past', 'Basil_qty_pastcol')
    serializer_class = basil_qty_pastSerializer
    
class basil_qtyViewSet(viewsets.ModelViewSet):
    queryset = basil_qty.objects.all().order_by('idBasil_order', 'Basil_qtycol')
    serializer_class = basil_qtySerializer

class basil_qty_futureViewSet(viewsets.ModelViewSet):
    queryset = basil_qty_future.objects.all().order_by('idBasil_order_future', 'Basil_qty_futurecol')
    serializer_class = basil_qty_futureSerializer

urls.py

"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin
from django.urls import path, include
from myapi.views import UI_Supermarket_Restaurant
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    path('admin/', admin.site.urls),
    path('UI_Supermarket_Restaurant', UI_Supermarket_Restaurant, name='UI_Supermarket_Restaurant'),
    path('', include('myapi.urls')),
    url(r'', include('myapi.urls')),
    
] 
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += staticfiles_urlpatterns()

urls.py

# myapi/urls.py
from django.urls import include, path
from rest_framework import routers
from . import views

router = routers.DefaultRouter()
router.register(r'romaine_qty_past', views.romaine_qty_pastViewSet)
router.register(r'romaine_qty', views.romaine_qtyViewSet)
router.register(r'romaine_qty_future', views.romaine_qty_futureViewSet)

router.register(r'kale_qty_past', views.kale_qty_pastViewSet)
router.register(r'kale_qty', views.kale_qtyViewSet)
router.register(r'kale_qty_future', views.kale_qty_futureViewSet)

router.register(r'basil_qty_past', views.basil_qty_pastViewSet)
router.register(r'basil_qty', views.basil_qtyViewSet)
router.register(r'basil_qty_future', views.basil_qty_futureViewSet)

# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
    path('', include(router.urls)),
    
]

apps.py

from django.apps import AppConfig


class MyapiConfig(AppConfig):
    name = 'myapi'

index.html

{% extends 'base.html' %}
{% load static %}
{% block content %}
    <div>
        <img class="fullwidth"
             src="/media/Happy_Greens.jpg"
             alt="Happy Vertical Farm Worker"
             title="Happy_Greens">
        <div class="fullwidth titletext titleposition">
            <p>Expeditor</p>
        </div>
        <div class="left">
            <p class="whtbg">Last Order</p>
            <table class="whtbg style">
                <thead>
                    <tr>
                        <th>Nomenclature</th>
                        <th>Qty</th>
                        <th>Unit</th>
                        <th>Deliver</th>
                        <th>PLU</th>
                        <th>Price</th>
                    </tr>
                <tbody>
                {% for item in query_results %}
                    <tr>
                        <td>Romaine</td>
                        <td>{{ item.Romaine_qty_pastcol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}    
                {% for item in query_results %}
                    <tr>
                        <td>Kale</td>
                        <td>{{ item.Kale_qty_pastcol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}    
                {% for item in query_results %}
                    <tr>
                        <td>Basil</td>
                        <td>{{ item.Basil_qty_pastcol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="2">Total</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>21</td>
                    </tr>
                </tfoot>
            </table>
            <br>
            <br>
            <br>
            <br>
            <br>
            <br>
            <button class="button leftbutton hover active" type="button" onclick="getVerticalFarm()">Approve</button>
        </div>
        <div class="center">
            <p class="whtbg">Current Order</p>
            <table class="whtbg style">
                <thead>
                    <tr>
                        <th>Nomenclature</th>
                        <th>Qty</th>
                        <th>Unit</th>
                        <th>Deliver</th>
                        <th>PLU</th>
                        <th>Price</th>
                    </tr>
                <tbody>
                {% for item in query_results %}
                    <tr>
                        <td>Romaine</td>
                        <td>{{ item.Romaine_qtycol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}
                {% for item in query_results %}
                    <tr>
                        <td>Kale</td>
                        <td>{{ item.Kale_qtycol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}    
                {% for item in query_results %}
                    <tr>
                        <td>Basil</td>
                        <td>{{ item.Basil_qtycol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}    
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="2">Total</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>21</td>
                    </tr>
                </tfoot>
            </table>
            <br>
            <br>
            <br>
            <br>
            <br>
            <br>
            <button class="button centerbutton hover active" type="button" onclick="">Amend</button>
        </div>
        <div class="right">
            <p class="whtbg">Next Order</p>
            <table class="whtbg style">
                <thead>
                    <tr>
                        <th>Nomenclature</th>
                        <th>Qty</th>
                        <th>Unit</th>
                        <th>Deliver</th>
                        <th>PLU</th>
                        <th>Price</th>
                    </tr>
                <tbody>
                {% for item in query_results %}
                    <tr>
                        <td>Romaine</td>
                        <td>{{ item.Romaine_qty_futurecol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}
                {% for item in query_results %}
                    <tr>
                        <td>Kale</td>
                        <td>{{ item.Kale_qty_futurecol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}    
                {% for item in query_results %}
                    <tr>
                        <td>Basil</td>
                        <td>{{ item.Basil_qty_futurecol }}</td>
                        <td>ea</td>
                        <td>11/1/20</td>
                        <td>4640</td>
                        <td>$100.80</td>
                    </tr>
                {% endfor %}
                    
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="2">Total</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>21</td>
                    </tr>
                </tfoot>
            </table>
            <br>
            <br>
            <br>
            <br>
            <br>
            <br>
            <button class="button hover active" type="button" onclick="">New Item</button>
        </div>
    </div>
       
{% endblock %}

base.html

{% load static %}

<!DOCTYPE html>
<html lang="en"
      class="body">
    
    <head>
        <!--Paul Polsinelli-->
        <meta charset="utf-8">
        <title>UI_Supermarket_Restaurant</title>
        <link href="{{STATIC_URL}}" type="text/css" rel="stylesheet" />
        <script src="{{STATIC_URL}}"></script>
        <style>.body {
    background-image: ;
    background-repeat: no-repeat;
    background-size: cover;
}
.fullwidth {
    position: absolute;
    width: 100%;
}
.titletext {
    color: white;
    font-family: fantasy;
    text-align: left;
    font-size: 1000%;
    text-shadow: 2px 2px black;
    top: -150px;
}
.titleposition {
    left: 23%;
}
.whtbg {
    background-color: white;
}
table.style {
    border: solid;
    border-color: black;
    text-align: left;
}
table.style th {
    background-color: green;
    border: solid;
    border-color:green;
    color: white;
}
table.style td {
    border: ;
    border-color:;
}
.left {
    position: absolute;
    left: 10%;
    top: 25%;
}
.center {
    position: absolute;
    left: 30%;
    top: 25%;
}
.right {
    position: absolute;
    left: 50%;
    top: 25%;
}
.lefttext {
    text-align: left;
}
.label {
    display: inline-block;
    width: 50%;
}
.form {
    width: 100%;
    height: 15%;
    margin: inherit;
    background: black;
    padding: 25px;
    color: white;
    font-weight: 500;
    font-size: 20px;
}
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 50%;
    width: 150px;
    cursor: pointer;
}
.hover {background-color: #3e8e41}

.active {
  background-color: #3e8e41;
  box-shadow: 0 5px lightgray;
  transform: translateY(4px);
}
.leftbutton {
    position: relative;
    right: -57%;
}
.centerbutton {
    position: relative;
    left: 30%;
}</style>
    </head>
    <script>
    function getVerticalFarm(){
        
    }
    </script>
    <body>
        {% block content %}
            replace me
        {% endblock %}
    <\body>
    
<\html>


Read more here: https://stackoverflow.com/questions/66271265/why-can-i-only-populate-1-row-in-webpage-with-django-framework

Content Attribution

This content was originally published by Paul Polsinelli at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: