我想使用外键过滤查询,但似乎它不愿认可。 status
可以是 'open'
或者 'closed'
。
models.py
class Status(models.Model):
status = models.CharField(primary_key=True, max_length=100)
class Incident(models.Model):
incident_date_reported = models.DateField('Date Reported', default=timezone.now)
status = models.ForeignKey(Status, default="open")
views.py
def index(request):
template = "index.html"
form = IncidentSearchForm(request.GET)
if request.method == 'GET':
form = IncidentSearchForm()
############## MY QUERY THAT DOESN'T LIKE THE FOREIGN KEY #############
incident_list = Incident.objects.filter(status = 'open').order_by('-incident_date_reported')
#######################################################################
context = { "form": form,
"incident_list": incident_list
}
return render(request, template, context)
__
应该可以工作...我不知道。 - user1807271