added basic search function
This commit is contained in:
parent
47dd122603
commit
674d41172e
4 changed files with 39 additions and 3 deletions
|
@ -15,4 +15,7 @@ class ProfileForm(forms.ModelForm):
|
|||
"text_field",
|
||||
"printing",
|
||||
"keep_me"
|
||||
]
|
||||
]
|
||||
|
||||
class SearchForm(forms.Form):
|
||||
name = forms.CharField(label='search name', max_length=1023)
|
21
fiches/templates/fiches/search.html
Normal file
21
fiches/templates/fiches/search.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{% extends "fiches/base.html" %}
|
||||
{% block content %}
|
||||
|
||||
<h2> Chercher quelqu'un.e dans l'annuaire </h2>
|
||||
<form method='post' action="">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Recherche">
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<ul>
|
||||
{% for profile in result %}
|
||||
<li><a href="{% url 'fiche' profile.id %}">{{profile.full_name}} {{profile.departement}}
|
||||
</a> </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -3,5 +3,6 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path('<int:id>',views.fiche, name='fiche'),
|
||||
path('edit',views.fiche_modif, name='fiche_modif')
|
||||
path('edit',views.fiche_modif, name='fiche_modif'),
|
||||
path('search',views.search, name='search')
|
||||
]
|
|
@ -2,7 +2,7 @@ from django.shortcuts import render
|
|||
from django.shortcuts import get_object_or_404,redirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from fiches.models import Profile
|
||||
from fiches.forms import ProfileForm
|
||||
from fiches.forms import ProfileForm, SearchForm
|
||||
from django.urls import reverse
|
||||
|
||||
# Create your views here.
|
||||
|
@ -25,3 +25,14 @@ def fiche_modif(request):
|
|||
form = ProfileForm(instance=profile)
|
||||
|
||||
return render(request,'fiches/fiches_modif.html',{"form":form})
|
||||
|
||||
@login_required
|
||||
def search(request):
|
||||
if request.method == 'POST':
|
||||
form = SearchForm(request.POST)
|
||||
if form.is_valid():
|
||||
result = Profile.objects.filter(full_name__icontains=form.cleaned_data['name'])
|
||||
return render(request,'fiches/search.html',{"form":form,"result":result})
|
||||
else:
|
||||
form = SearchForm()
|
||||
return render(request,'fiches/search.html',{"form":form})
|
||||
|
|
Loading…
Add table
Reference in a new issue