Created
July 21, 2018 16:58
-
-
Save renjithsraj/d18199d070a597745f6f07c0fe711802 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#home.html | |
<!--Timeline header area start --> | |
<form action="." method="post" name="category_form"> | |
{% csrf_token %} | |
<div class="post-list-header"> | |
<span class="post-list-title">Latest stories</span> | |
<select class="frm-input" name="category_name" id="category_name"> | |
<option value="dummy">select category</option> | |
{% for cat in categories %} | |
<option value="{{cat.slug}}">{{cat.name}}</option> | |
{% endfor %} | |
</select> | |
</div> | |
</form> | |
!--Timeline header area end --> | |
<script> | |
$(document).ready(function(){ | |
$("#category_name").change(function(){ | |
this.form.submit(); | |
}); | |
}); | |
</script> | |
views.py | |
def home(request): | |
if request.POST: | |
print (request.POST['category_name']) | |
posts = Model.objects.filter(category=Category.objects.get(slug=request.POST['category_name'])) | |
request.session['category_name'] = request.POST['category_name'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment