Added a column type for handling foreign keys in grid views.
authorStephen Burrows <stephen.r.burrows@gmail.com>
Tue, 5 Apr 2011 18:43:39 +0000 (14:43 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Wed, 6 Apr 2011 20:58:32 +0000 (16:58 -0400)
contrib/gilbert/media/gilbert/plugins/models.js
contrib/gilbert/plugins/models.py

index ab36f36..79ef0b3 100644 (file)
@@ -55,6 +55,16 @@ Ext.override(Gilbert.lib.models.Model, {
 });
 
 
+Gilbert.lib.plugins.models.ui.ForeignKeyColumn = Ext.extend(Ext.grid.Column, {
+       renderer: function(v) {
+               return v.__unicode__
+       }
+})
+
+
+Ext.grid.Column.types['foreignkeycolumn'] = Gilbert.lib.plugins.models.ui.ForeignKeyColumn
+
+
 Gilbert.lib.plugins.models.ui.ModelPanel = Ext.extend(Ext.Panel, {
        constructor: function (model, plugin, config) {
                var model = this.model = model;
index e3d559a..5bf2550 100644 (file)
@@ -120,6 +120,7 @@ class ModelAdmin(Plugin):
        @property
        def data_columns_spec(self):
                spec = []
+               
                for field_name in self.data_columns:
                        column = {
                                'dataIndex': field_name,
@@ -132,6 +133,8 @@ class ModelAdmin(Plugin):
                                column['sortable'] = True
                        if field_name in self.data_editable_columns:
                                column['editable'] = True
+                       if field_name in [field.name for field in self.model_meta.fields if isinstance(field.rel, ManyToOneRel)]:
+                               column['xtype'] = 'foreignkeycolumn'
                        spec.append(column)
                return spec