querry to pass jquery variable value to django template, please responce me need help one of yours...

559 views
Skip to first unread message

Jaiprakash Singh

unread,
Aug 1, 2014, 8:59:13 AM8/1/14
to django-d...@googlegroups.com
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-template
http://www.tangowithdjango.com/book/chapters/ajax.html
and  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...


 

Daniele Procida

unread,
Aug 1, 2014, 9:01:41 AM8/1/14
to Django Developers
On Fri, Aug 1, 2014, Jaiprakash Singh <jaipr...@wisepromo.com> wrote:

>unfortunately, i am not able find the solution, so require some hints from
>all of u guys

You'll get answers to your questions on the django-users email list, <django-d...@googlegroups.com> - the web interface is <https://groups.google.com/forum/#!forum/django-users>.

The list you've posted to is django-developers, an email list is for the discussion of the development of Django itself.

You might also find helpful the #django IRC channel on irc.freenode.net.

I hope that helps,

Daniele

Reply all
Reply to author
Forward
0 new messages