I want to print phoneNumber, spendingScore, annualIncome of all the objects (Customer) under a particular user (Vendor)!
models.py:
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class CustomerBill(models.Model):
vendor = models.ForeignKey(User, on_delete=models.CASCADE)
phoneNumber = models.CharField(max_length=14, blank=False)
spendingScore = models.IntegerField()
annualIncome = models.IntegerField()
def __str__(self):
return self.phoneNumber
views.py:
from django.shortcuts import render, redirect
from django.contrib.auth.models import User, auth
from django.contrib import messages
from . models import CustomerBill
def customerDatabase(request):
customerDataList = CustomerBill.objects.filter(
vendor=request.user).values()
context = {
'customerData': customerDataList,
}
return render(request, 'database.html', context)
html:
<body>
{% include 'navbar.html' %}
<br>
<h2 style="text-align: center;">Customer Database</h2>
<br>
<table style="width: 60%; margin: 0 auto;">
<thead>
<tr>
<th>Serial No.</th>
<th>Phone Number</th>
<th>Spending Score</th>
<th>Annual Income</th>
</tr>
</thead>
<tbody>
{% for i in context %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{i.phoneNumber}}</td>
<td>{{i.spendingScore}}</td>
<td>{{i.annualIncome}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
Can anyone help me out? a little urgent!