queryset-didn't show result.

9 views
Skip to first unread message

DjgoNy

unread,
Oct 25, 2012, 10:30:27 AM10/25/12
to django...@googlegroups.com
I have a project where i have to extract data from database whenever i click on it.
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 - 123456789SMOKINGWEIGHTBP
DATEDATENEW 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.

Reply all
Reply to author
Forward
0 new messages