I'm trying to create a simple form that pulls up a record by asking its ID in the form.
views.py
class Bill(models.Model):
"""
Represents a single purchase made by a customer at a business.
"""
business = models.ForeignKey(Businesses)
customer = models.ForeignKey(User, blank=True, null=True)
charge = models.ForeignKey(Charge, blank=True, null=True)
amount = models.IntegerField(verbose_name='Purchase amount (in cents)',
validators=[MinValueValidator(0)])
tip = models.IntegerField(verbose_name='Tip amount (in cents)',
validators=[MinValueValidator(0)])
comments = models.CharField(max_length=255, blank=True, null=True)
timestamp = models.DateTimeField(auto_now_add=True)
forms.py
from django import forms from django.forms import ModelForm from transactions.models import Bill
class BillSelectForm(ModelForm):
class Meta:
model = Bill
fields = ('id',)
views.py
@login_required(login_url='/sign-in/')
def select_bill(request):
"""
Finds a bill based on its ID number.
"""
if request.method == 'POST':
form = BillSelectForm(request.POST)
if form.is_valid():
pass
# look up db for id number
# go to bill view page if id found AND bill not paid
# go back to same page and create message saying wrong bill
else:
form = BillSelectForm()
return render(request, 'bill_select.html', {'form': form})
However, on the template, when I use {{ form.as_p }}, I'm seeing nothing at all. Thoughts?