Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Category(models.Model):
- name = models.CharField(max_length=40)
- class Item(models.Model):
- name = models.CharField(max_length=40)
- category = models.ForeignKey(Category)
- class Demo(models.Model):
- name = models.CharField(max_length=40)
- category = models.ForeignKey(Category)
- item = models.ForeignKey(Item)
- <script charset="utf-8" type="text/javascript">
- $(function(){
- $("select#id_category").change(function(){
- $.getJSON("/items/",{id: $(this).val(), view: 'json'}, function(j) {
- var options = '<option value="">-------- </option>';
- for (var i = 0; i < j.length; i++) {
- options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
- }
- $("#id_item").html(options);
- $("#id_item option:first").attr('selected', 'selected');
- })
- $("#id_category").attr('selected', 'selected');
- })
- })
- </script>
Add Comment
Please, Sign In to add comment