django jqgrid什么都没有出现

时间:2012-07-11 17:58:30

标签: jquery django jqgrid

我上周一直在努力找出Jqgrid for Django。我正在使用此安装:http://pypi.python.org/pypi/django-gems/

我的代码没有任何错误但没有出现任何错误:(

my grids.py

    from django_gems.jqgrid import JqGrid
    from shopping.models import Shopping

    class ShoppingGrid(JqGrid):
      model = Shopping
      fields = ["id", "name", "price"]
      url = reverse("shopping_grid_handler")
      colmodel_overrides = {
       "id": {
          "hidden": True
        },
        "name": {
        "label": "Name",
        "sortable": True,
        "searchoptions": {
          "sopt": ["eq",]
        },
       "price": {
          "label": "Price"
        }
       }

models.py

from django.db import models

# Create your models here.

class Shopping(models.Model):
    name    =   models.CharField(max_length=200)
    slug    =   models.SlugField(max_length=200, unique=True)
    size    =   models.CharField(max_length=15)
    color   =   models.CharField(max_length=15)
    price   =   models.ForeignKey('Price')
    description = models.TextField(blank=True)

    def __unicode__(self):
        return self.name

class Price(models.Model):

    cost = models.CharField(max_length=200)
    description = models.TextField(blank=True)

    def __unicode__(self):
        return self.name

views.py

def shopping_grid_handler(request):
        from grids import ShoppingGrid
        from django import http
        grid = ShoppingGrid()
        return http.HttpResponse(grid.get_json(request),
mimetype="application/json")

def shopping_grid_config(request):
        from grids import ShoppingGrid
        from django import http
        grid = ShoppingGrid()
        return http.HttpResponse(grid.get_config(), mimetype="application/json")

urls.py

  

来自django.conf.urls.defaults import * from   django.views.generic.simple从中导入direct_to_template   shopping.views import shopping_grid_handler,shopping_grid_config

     

urlpatterns = patterns(“”,       url(r“^ $”,direct_to_template,{“template”:“shopping / shopping.html”},name =“shopping”),

     

url(r“^ shopping / $”,direct_to_template,{“template”:“shopping / shopping.html”},> name =“shopping”),

     

URL(R “^ ShoppingGrid / $”,   使用direct_to_template,名字= “shopping_grid_handler”),

     

URL(R “^ ShoppingGrid / cfg中/ $”,shopping_grid_config,   名称= “shopping_grid_config”),

shopping.html

{% block extra_style %}
<link rel="stylesheet" href="{{ STATIC_URL }}css/style.css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" />
{% endblock extra_style %}

    {% block right1 %} 
<table id="list_doc"></table>
<div id="pager_doc"></div>

    {% endblock right1 %}    


{% block extra_script %}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="{{ STATIC_URL }}js/libs/jquery-1.7.2.min.js"><\/script>')</script>

<script src="{{ STATIC_URL }}js/libs/bootstrap/bootstrap.min.js"></script>
<script src="{{ STATIC_URL }}js/script.js"></script>
<script src="{{ STATIC_URL }}js/libs/modernizr-2.5.3.min.js"></script>

<script src="{{ STATIC_URL }}js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="{{ STATIC_URL }}js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="{{ STATIC_URL }}js/jquery.jqGrid.min.js" type="text/javascript"></script>

<script type="text/javascript">

{{{
$(function () {
    $.getJSON("{% url shopping_grid_config %}", function(data){
        $("#mygrid")
            .jqGrid(data)
            .navGrid('#pager', 
                {add: false, edit: false, del: false, view: true},
        {}, // edit options
        {}, // add options
        {}, // del options 
        { multipleSearch:true, closeOnEscape:true }, // search options 
        { jqModal:false, closeOnEscape:true} // view options 
        );
    });
});
}}}



</script>
{% endblock extra_script %}

0 个答案:

没有答案