From d8e465dd94de3bf7d5b50ff9fba8375ef42cd79c Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Tue, 5 Apr 2011 14:43:39 -0400 Subject: [PATCH] Added a column type for handling foreign keys in grid views. --- contrib/gilbert/media/gilbert/plugins/models.js | 10 ++++++++++ contrib/gilbert/plugins/models.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/contrib/gilbert/media/gilbert/plugins/models.js b/contrib/gilbert/media/gilbert/plugins/models.js index ab36f36..79ef0b3 100644 --- a/contrib/gilbert/media/gilbert/plugins/models.js +++ b/contrib/gilbert/media/gilbert/plugins/models.js @@ -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; diff --git a/contrib/gilbert/plugins/models.py b/contrib/gilbert/plugins/models.py index e3d559a..5bf2550 100644 --- a/contrib/gilbert/plugins/models.py +++ b/contrib/gilbert/plugins/models.py @@ -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 -- 2.20.1