在递归时我有一个心理障碍。所以,我不确定我是否正在思考,或者是否有更好的方法来做到这一点。我有访问模型和访问者模型:
class Inquiry (models.Model):
arrival = models.DateField("arrival date")
departure = models.DateField("departure date")
organization = models.CharField(max_length=80)
visitors = models.PositiveSmallIntegerField()
class Visitor (models.Model):
inquiry = models.ForeignKey(Inquiry)
surname = models.CharField(max_length=80)
givenname = models.CharField("given name",max_length=80)
middlename = models.CharField(max_length=80, null=True)
我希望查询表格询问访问者的数量(以及其他内容),然后在单独的网页上为每位访问者生成表格。换句话说,对于三个访问者,用户需要点击提交四次:一次用于查询表单,然后一次用于三个访问者表单。
我在想:
def inquiry(request):
if request.method == "POST":
inquiry_form = InquiryForm(request.POST)
if inquiry_form.is_valid():
inquiry = inquiry_form.save()
visitors = inquiry.visitors
return HttpResponseRedirect("/resources/visitors/bios/%s" % (inquiry.id, visitors,)
...
def contact(request,inquiry, visitors):
if visitors > 0:
if request.method == "POST":
visitor_form = VisitorForm(request.POST)
if visitor_form.is_valid():
visitor = visitor_form.save()
visitors -= 1
return HttpResponseRedirect("/resources/visitors/bios/%s" % (inquiry, visitors,)
...
else:
return
但我知道我错过了几个人。 (我也看了一下表格向导,但我不确定这对我有帮助。)