I am using django 1.4 together with jqgrid
from django_gems
package
The following code is trying to bring the virtual
column onto the grid
by concatenating first and last name.
However it fails with
Cannot resolve keyword client__get_fullname
into field.
Is there any acceptable way to achieve this?
class Car(models.Model):
number = models.CharField(max_length = 50)
client = models.ForeignKey('Client')
class Client(models.Model):
first_name = models.CharField(max_length = 50)
last_name = models.CharField(max_length = 50)
def get_fullname(self):
return '%s %s' % (self.first_name, self.last_name)
from django_gems.jqgrid
import JqGrid
class CarGrid(JqGrid):
queryset = Car.objects.all()
fields = ['number', 'client__get_fullname']
jqgrid config = {
"altRows": true,
"rowList": [10, 25, 50, 100],
"sortname": "id",
"viewrecords": true,
"autowidth": false,
"forcefit": false,
"shrinkToFit": false,
"height": "auto",
"colModel": [{
"index": "id",
"editable": false,
"name": "id",
"label": "ID"
}, {
"index": "number",
"editable": false,
"name": "number",
"label": "number"
}, {
"index": "first_name",
"editable": false,
"name": "client__first_name",
"label": "first name"
}],
"caption": "Cars",
"datatype": "json",
"gridview": true,
"sortorder": "asc",
"viewsortcols": true,
"url": "main/examplegrid",
"rowNum": 10,
"pager": "#pager",
"jsonReader": {
"repeatitems": false
}
}
sample data = {
"total": 1,
"records": 1,
"rows": [{
"client__first_name": "Bill",
"client__last_name": "Clinton",
"id": 1,
"number": "111222"
}],
"page": 1
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…