一周前,我从pythond和django开始。观看了很多教程,并在这里四处看看。
这是我的模特。两张表,一张用于客户,一张用于应用程序。这些应用程序已映射到客户。
class Customer(models.Model):
customer = models.CharField(max_length=255)
description = models.TextField(null=True)
def __str__(self):
return self.customer
class Application(models.Model):
application = models.CharField(max_length=255)
description = models.TextField(null=True)
customer_id = models.ForeignKey('Customer',on_delete=models.PROTECT,blank=True, null=True)
def __str__(self):
return self.application
这是我创建新客户的视图功能
def new_customer_view(request, customer_id):
form = CustomerForm(request.POST or None)
if form.is_valid():
form.save()
form = CustomerForm()
context = {
'customer': Customer.objects.get()
}
return render(request, 'forcast/new_customer.html', context )
当我尝试访问表单时,我得到:
TypeError: new_customer_view() missing 1 required positional argument: 'customer_id'