Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I filter data in this way?
    text
    copied!<p>models.py:</p> <pre><code>class InjuredLocation(models.Model): reportperson = models.ForeignKey(ReportPerson) mark1 = models.BooleanField('Mark1', default=False) mark2 = models.BooleanField('Mark2', default=False) mark3 = models.BooleanField('Mark3', default=False) class Report(models.Model): user = models.ForeignKey(User, null=False) report_number = models.CharField('report Number', max_length=100) class ReportPerson(models.Model): report = models.ForeignKey(Report) action_type = models.CharField(max_length=100, choices=ACTION_TYPE) name = models.CharField('Name', max_length=100) </code></pre> <p>This is my three models, I want to filter the data from <code>InjuredLocation</code> models.</p> <ol> <li>Reportperson table contain report id and name field of that table could be multiple.Each report can have multiple names.</li> <li>I want to filter the data from <code>InjuredLocation</code> table with reference to <code>reportperson_id</code>.</li> <li>The filtered data should be for the equivalent report.</li> </ol> <p>tried:</p> <pre><code> injury_list = [] reportperson = ReportPerson.objects.filter(report=report_id, action_type="involved") injuary_mark = InjuredLocation.objects.filter(pk=reportperson) for injuary in injuary_mark: mark = InjuredLocation.objects.get(pk=injuary.id) marklist={'mark':mark} injury_list.append(marklist) </code></pre> <p>I am getting this error "(1242, 'Subquery returns more than 1 row')" in 5th line,if Reportperson table have more than one name. </p> <p>update:</p> <pre><code>injuery_list = [] injuries = InjuredLocation.objects.filter(reportperson__report=report_id, reportperson__action_type="involved") for reportperson in injuries: injun = InjuredLocation.objects.get(pk=reportperson.id) list_inju = {'person': injun} injuery_list.append(list_inju) </code></pre> <p>Able to take the objects from InjuredLocation models,in template i rendered it but problem is "it should render against reportperson_id,instead it is rendering all" for example if InjuredLocation models have reportperson_id=1,mark1=0 &amp; mark2=1 and for reportperson_id=2,mark1=1 &amp; mark2=0 it is rendering all like this "1 1" for both reportperson_id.The expected output is 0 1 and 1 0.What ever selected are all comes to display for all reportperson_id.</p> <p>template is</p> <pre><code>{%for injuary_mark in injuery_list%} {%if injuary_mark.person.mark1 %}&lt;img style="float: right; margin:5px 4px -35px 0;" src="{{BASE_URL}}/static/images/red-cross.png"&gt; {% endif %} {%if injuary_mark.person.mark2 %}&lt;img style="float: right;margin:5px 8px -35px -8px;" src="{{BASE_URL}}/static/images/red-cross.png"&gt; {% endif %} {%endfor%} </code></pre> <p><strong>Last update:</strong></p> <p>I want to show the details in InjuredLocation models against id in the Reportperson models.This is from a single report,see the Report models in the figure.</p> <p>All the three models with data i pasted below.</p> <p><img src="https://i.stack.imgur.com/Ha57h.png" alt="Reportperson model"> <img src="https://i.stack.imgur.com/XDKqz.png" alt="InjuredLocation model"> <img src="https://i.stack.imgur.com/F1Zfw.png" alt="Report model"></p> <p>What i required as output is,a tab will be dynamically created when a row in InjuredLocation model is created against id in Reportperson table.I want to show the mark from InjuredLocation table against their respective id from Reportperson table in their respective tabs.Now all the mark whatever created against id in Reportperson model are shown in all tabs.Assume mark for id=1 is empty and Marks for id=2 and id=3 are their in database,as per requirement tab1 should not show any data,but now tab1 is showing data of tab2 and tab3 from id=2 and id=3's data.Need help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload