Guest User

Untitled

a guest
Jun 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class Category(models.Model):
  2. name = models.CharField(max_length=40)
  3.  
  4. class Item(models.Model):
  5. name = models.CharField(max_length=40)
  6. category = models.ForeignKey(Category)
  7.  
  8. class Demo(models.Model):
  9. name = models.CharField(max_length=40)
  10. category = models.ForeignKey(Category)
  11. item = models.ForeignKey(Item)
  12.  
  13. <script charset="utf-8" type="text/javascript">
  14. $(function(){
  15. $("select#id_category").change(function(){
  16. $.getJSON("/items/",{id: $(this).val(), view: 'json'}, function(j) {
  17. var options = '<option value="">--------&nbsp;</option>';
  18. for (var i = 0; i < j.length; i++) {
  19. options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
  20. }
  21. $("#id_item").html(options);
  22. $("#id_item option:first").attr('selected', 'selected');
  23. })
  24. $("#id_category").attr('selected', 'selected');
  25. })
  26. })
  27. </script>
Add Comment
Please, Sign In to add comment