On ne filtre les départements que si on en donne
This commit is contained in:
parent
b3f7e944c3
commit
4e7fe564cf
1 changed files with 6 additions and 2 deletions
|
@ -130,13 +130,17 @@ class HomeView(FormView):
|
|||
def form_valid(self, form):
|
||||
name = form.cleaned_data["name"]
|
||||
promotion = form.cleaned_data["year"]
|
||||
depts = form.cleaned_data["department"]
|
||||
result = Profile.objects.filter(
|
||||
Q(full_name__icontains=name)
|
||||
| Q(nickname__icontains=name)
|
||||
| Q(user__username__icontains=name)
|
||||
).filter(department__in=form.cleaned_data["department"])
|
||||
)
|
||||
|
||||
if promotion is not None:
|
||||
if depts:
|
||||
result = result.filter(department__in=depts)
|
||||
|
||||
if promotion:
|
||||
result = result.filter(promotion=promotion)
|
||||
|
||||
return self.render_to_response(self.get_context_data(result=result))
|
||||
|
|
Loading…
Add table
Reference in a new issue