Wednesday, November 2, 2011

Re: Django + Ajax/Javascript

You could pass the values from the view to the template and use javascript (I would suggest using jQuery) if there are only a few options. I would suggest using Dajax (dajaxproject.com) for your AJAX commands. It is really easy to plug into Django, and you should get familiar with it and the jQuery javascript framework. They work very well for making the UI fun and easy. There is also jQuery-UI which builds on the jQuery library with tons more user interface options, like calendar pickers, sliders, etc. Good stuff! :-)

Furbeenator

On Wed, Nov 2, 2011 at 5:42 AM, Felix Wagner <hsaldinor@googlemail.com> wrote:
Hi,

I have the following model layout:

class A(models.model):
   options = models.ManyToManyField(OptionSet, blank=True, null=True)
   values = models.ManyToManyField(Value, blank=True, null=True)

class OptionSet(models.model):
   name = models.TextField(unique=True)
   values = models.ManyToManyField(Value)

   def __unicode__(self):
       return '%s' % self.name

class Value(models.Model):
   name = models.TextField()
   key = models.ForeignKey(Key, related_name='values')

class Key(models.Model):
   name = models.TextField(unique=True)

And my forms.py looks like this:

class A_Form(ModelForm):
   values =
forms.ModelMultipleChoiceField(queryset=Value.objects.all(),
widget=CheckboxSelectMultiple, label="Einzelne Werte", required=False)
   options =
forms.ModelMultipleChoiceField(queryset=OptionSet.objects.all(),
widget=CheckboxSelectMultiple, label="Optionen Sets", required=False)

Template:

<form action="." method="POST">{% csrf_token %}
   {{ form.as_table }}
   <input type="submit" value="Update"/>
</form>

I use that form with a generic update view! I'm new to javascript/ajax
to be honest never did something in javascript/ajax. What I want to do
is on mouseover on the options name it should show all the values for
that option set. How would one accomplish this (either with or without
ajax)?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment