python - issue in search and display the report -


views.py

def search(request):     """""""      if 'search' in request.post:                 search_keyword = request.post.get('search_keyword')                 reports = reports.filter(q(incident_description__icontains=search_keyword) | q(incident_number__icontains=search_keyword) | q(reportperson__name__icontains=search_keyword))         """""""     return render(request,'search.html',{'searchform':searchform}) 

models.py

class report(models.model):     user = models.foreignkey(user, null=false)     incident_number = models.charfield('incident number', max_length=100)     incident_description = models.textfield('incident description', null=true, blank=true)  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) 

the above view perform keyword search(search on data in model field) report model , reportperson model.

a report stored in report model can have more 2 reportperson details.

in database values this,

if values in report table , reportperson table in image,report model

report model

reportperson model

reportperson model

here,a report having 2 reportperson detail.if perform search case,the same report displayed 2 times.depence on number of reportperson detail,the count of showing same report showing again , again varies.

i want know how handle this,this happening because using name search reportperson table.problem happening report=reports.filter(....| q(reportperson__name__icontains=search_keyword)),.need help.

what select distinct ? (see https://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct)


Comments