X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/82fbb035b6b18ed8ea90621c8fa78022e8ef1dfb..a2d75eae2cab588a28155b9c901935aa8d664d5f:/contrib/gilbert/plugins/models.py?ds=sidebyside diff --git a/contrib/gilbert/plugins/models.py b/contrib/gilbert/plugins/models.py index ae97ee7..ee13989 100644 --- a/contrib/gilbert/plugins/models.py +++ b/contrib/gilbert/plugins/models.py @@ -1,6 +1,7 @@ from django.conf import settings from django.contrib.admin.util import lookup_field, label_for_field, display_for_field, NestedObjects from django.core.exceptions import PermissionDenied +from django.db import router from django.db.models import Q from django.db.models.fields.related import ManyToOneRel from django.db.models.fields.files import FieldFile, ImageFieldFile, FileField @@ -10,7 +11,7 @@ from django.utils import simplejson as json from django.utils.encoding import smart_unicode from .base import Plugin from ..extdirect import ext_action, ext_method -import operator, staticmedia +import operator @ext_action(name='models') @@ -24,8 +25,8 @@ class Models(Plugin): @property def index_js_urls(self): return super(Models, self).index_js_urls + [ - staticmedia.url('gilbert/extjs/examples/ux/SearchField.js'), - staticmedia.url('gilbert/plugins/models.js'), + settings.STATIC_URL + 'gilbert/extjs/examples/ux/SearchField.js', + settings.STATIC_URL + 'gilbert/plugins/models.js', ] @property @@ -65,7 +66,7 @@ class ModelAdmin(Plugin): def data_serialize_model_instance(cls, obj): return { 'app_label': obj._meta.app_label, - 'name': obj._meta.object_name, + 'name': obj._meta.module_name, 'pk': obj.pk, '__unicode__': unicode(obj), } @@ -120,6 +121,7 @@ class ModelAdmin(Plugin): @property def data_columns_spec(self): spec = [] + for field_name in self.data_columns: column = { 'dataIndex': field_name, @@ -132,6 +134,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 @@ -375,9 +379,8 @@ class ModelAdmin(Plugin): pks = [pks] objs = [self.model._default_manager.all().get(pk=pk) for pk in pks] - collector = NestedObjects() - - for obj in objs: - obj._collect_sub_objects(collector) + using = router.db_for_write(self.model) + collector = NestedObjects(using=using) + collector.collect(objs) return collector.nested(self.data_serialize_model_instance) \ No newline at end of file