我正在构建一个测试应用程序,我需要执行一系列测试步骤。关于我的关注,我有几个问题。
创建完整测试后,默认情况下应创建所有测试步骤。
当用户选择部分测试时,我将如何过滤测试步骤?
在我的测试详细信息模板中,我需要经历一系列问题,这些问题将是发送请求并从api接收响应的形式。 我想知道如何使用表单集或其他方式传递到下一个表单。例如,第1步-进行说明,请单击“下一步”。接下来是提交请求的表单提交,下一个表单将填充django模板。
非常感谢您的帮助。
View.py
def create_test(request, id=None):
form = PrinterTestForm(request.POST or None)
if form.is_valid():
instance = form.save(commit=False)
instance.printer = Printer.objects.get(id=id)
instance.save()
# test = Test.objects.get_object_or_404(Test, id=instance.id)
return redirect(instance.get_absolute_url())
else:
test_name = None
test_type = None
test = None
context = {
"form": form,
}
return render(request, "testing/create_test.html", context)
def test_detail(request, id):
test_instance = get_object_or_404(Test, id=id)
printer_status_check = printer_check(test_instance)
stepOne =
context = {
"test": test_instance,
'printer_status': printer_status_check
}
return render(request, "testing/test_detail.html", context)
def printer_check(request):
device_dns = request.printer.device_dns
status = get_status_test(device_dns)
return status
models.py
TESTCHOICES = (
('Full Test', 'full_test'),
('Partial Test', 'partial_test')
)
TEST_REGEX = '^[a-zA-Z0-9.+-_ ]*$'
class Test(models.Model):
test_name = models.CharField(max_length=120, validators=[RegexValidator(regex=TEST_REGEX, message="Only Alphanumeric characters allowed in Test Name", code="invalid_test_name")])
test_type = models.CharField(max_length=32, choices=TESTCHOICES, default='Full Test')
printer = models.ForeignKey(Printer, on_delete=models.CASCADE)
timestamp = models.DateTimeField(auto_now=True)
def __str__(self):
return self.test_name
def get_absolute_url(self):
return reverse('testing:test_detail', kwargs={'id': self.id })
class TestStep(models.Model):
test = models.ForeignKey(Test, on_delete=models.CASCADE)
test_type_step = models.CharField(max_length=120, choices=TESTCHOICES)
test_step_name = models.CharField(max_length=240)