I have created a simple Django application which tries to access table named fruits present in PostgreSQL database and display its contents. I followed the official Django documentation and implemented below code as far as I understand. But below procedure is incomplete I believe as fruits.objects.all() is failing to fetch any data. I am missing something can anybody point it out any help would be appreciated.
Table: fruits
models.py
from django.db import models
class fruits(models.Model):
ID = models.CharField(max_length=20)
Name = models.CharField(max_length=20)
def __str__(self):
return self.Name
views.py
from database.models import fruits
def index(request):
data = fruits.objects.all()
print(len(data))
for item in data:
print(item)
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<database_name>',
'USER': '<user_name>',
'PASSWORD': '<password>',
'HOST': '<host_name>',
'PORT': '',
}
}

class fruitsshould becomeclass Fruit. Class attributes are by convention written insnake_case, thusidinstead ofID,nameinstead ofName. Check PEP 8 and follow coding convetions.