getting database values using get_object_or_404
I am using get_object_or_404 to try to get a list of values from my
database. I'm trying to filter the get_object_or_404 function for the
state variable to grab only values that are associated with the
disease_id. The code below does not work (it grabs all values in the State
table. Any ideas?
views.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)
models.py
class State(models.Model):
state = models.CharField(max_length=300, verbose_name='state')
relevantdisease = models.ForeignKey(Disease, verbose_name="disease")
No comments:
Post a Comment