我正在get_object_or_404
尝试从我的数据库中获取值列表。我正在尝试过滤get_object_or_404
状态变量的函数以仅获取与disease_id
. 下面的代码不起作用(它获取 State 表中的所有值。有什么想法吗?
视图.py
def option(request, disease_id, state_id):
state = get_object_or_404(State, relevantdisease=disease_id)
disease = get_object_or_404(Disease, pk=disease_id)
context = {'state': state, 'disease':disease }
return render(request, "option.html", context)
模型.py
class State(models.Model):
state = models.CharField(max_length=300, verbose_name='state')
relevantdisease = models.ForeignKey(Disease, verbose_name="disease")