hello all,
i am working on project for learning purpose, i have got stuck on a small logic , i have tried lot to find the solution ,
gone to url like
http://www.sprklab.com/notes/13-passing-arguments-to-functions-in-django-templatehttp://www.tangowithdjango.com/book/chapters/ajax.htmland many more
unfortunately, i am not able find the solution, so require some hints from all of u guys
so i m applying a logic under following
1) i m selecting a option form a select menu
2) on select the option eant to get the selected value
3) now this selected , i want to pass through a template tag for query purpose from database.
my small part of logic is under
#######################
<select onchange="change()" name="tclass" class="target">
<option value="-1">Select Class</option>
<option value="1">Class I</option>
<option value="2">Class II</option>
</select>
##############################################
<script>
$( ".target" ).change(function () {
var id = $(this).val();
var dataString = 'id='+ id;
{% get_latest bookstoreapp.Book 5 as recent_posts %} ====>>> i want to use above $id or id instead of 5 here
})
</script>
for more info sending my templates/get_latest.py
#########################################################
from django.template import Library, Node
from django.db.models import get_model
register = Library()
class LatestContentNode(Node):
def __init__(self, model, num, varname):
self.num, self.varname = int(num), varname
self.model = get_model(*model.split('.'))
def render(self, context):
context[self.varname] = self.model.objects.filter(pk = self.num)
return ''
def get_latest(parser, token):
bits = token.contents.split()
if len(bits) != 5:
raise TemplateSyntaxError, "get_latest tag takes exactly four arguments"
if bits[3] != 'as':
raise TemplateSyntaxError, "third argument to get_latest tag must be 'as'"
return LatestContentNode(bits[1], bits[2], bits[4])
get_latest = register.tag(get_latest)
################3
please help guys...