It should be shown in a table and it will be shown individually but whenever i use queryset in my view it didn't show anything
and when i commented the queryset then it will be shown all the listed data but not individually. in other word not the right data but there is a result.
what went wrong with my program.
view.py
class SolutionView(ListView):
template_name="Solution_list.html"
model = Solution
form_class = SolutionForm
context_object_name = "solutions"
def get_context_data(self, **kwargs):
context = super(SolutionView, self).get_context_data(**kwargs)
context['person_NOID']=self.kwargs['person_NOID']
tilstande =Solution.objects.filter( NOID= self.kwargs['person_NOID'])
return context
def get_queryset(self, **kwargs):
queryset =Solution.objects.filter(CPR = self.kwargs['person_NOID'])
return queryset
def form_valid(self, queryset):
queryset.save()
return HttpResponseRedirect(reverse("index"))
Solution_list.html
<html>
<head>
<body>
<h2 style="text-align: left; margin-left: 5%;">Solution</h2>
{% if solutions%}
<div id ="person_table">
<form action="{% url Solution_view person_NOID %}" method="post">
{% csrf_token %}
<table border="1" id="thetable">
<thead>
<tr>
<th>NOID {{ person_NOID }}</th>
<th>SMOKING</th>
<th>WEIGHT</th>
<th>BP</th>
</tr>
</thead>
<tbody>
{% for solution in solutions %}
<tr>
<td>{{ solution.NEW_DATE }}</td>
<td><input type="text" name="solution" id="solution{{ forloop.counter }}" value="{{ solution.SMOKING}}" /></td>
<td><input type="text" name="solution" id="solution{{ forloop.counter }}" value="{{ solution.WEIGHT}}" /></td>
<td><input type="text" name="solution" id="solution{{ forloop.counter }}" value="{{ solution.BP}}" /></td>
<td><input type="text" name="solution" id="solution{{ forloop.counter }}" value="{{ solution.BP}}" /></td>
</tr>
{% endfor %}
</tbody>
</table>
<input type="submit" value="Save" />
</form>
{% else %}
<p>No Data.</p>
{% endif %}
</body>
</head>
</html>
I want it to look something like this.
| NOID - 123456789 | SMOKING | WEIGHT | BP |
|---|---|---|---|
| DATE | DATE | NEW DATE |
whereby everytime they came a new date it will be shown in DATE-first date DATE-next date DATE-and so on.
And when user click on NEW DATE then the result will be shown on the appropriate table ei: smoking , weight, BP.
Thank you so much.
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/BjwwjV1ZS4YJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment