summaryrefslogtreecommitdiff
path: root/lib/grappelli/views/related.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2010-10-23 19:46:20 -0400
committerluxagraf <sng@luxagraf.net>2010-10-23 19:46:20 -0400
commitc59a2a69fb38b92b6c45bcf7431d2b1a3c5dce3c (patch)
tree2fc44ca867839d5e591e21467b6e4526f7a9f080 /lib/grappelli/views/related.py
parented77da873e675f02f12cbab9be27f342f825444b (diff)
added grappelli, filebrowser, chunks and tagging to lcal repo
Diffstat (limited to 'lib/grappelli/views/related.py')
-rw-r--r--lib/grappelli/views/related.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/grappelli/views/related.py b/lib/grappelli/views/related.py
new file mode 100644
index 0000000..81622ab
--- /dev/null
+++ b/lib/grappelli/views/related.py
@@ -0,0 +1,51 @@
+# coding: utf-8
+
+from django.http import HttpResponse
+from django.db import models
+
+def related_lookup(request):
+
+ if request.method == 'GET':
+ if request.GET.has_key('object_id') and request.GET.has_key('app_label') and request.GET.has_key('model_name'):
+ object_id = request.GET.get('object_id')
+ app_label = request.GET.get('app_label')
+ model_name = request.GET.get('model_name')
+ if object_id:
+ try:
+ model = models.get_model(app_label, model_name)
+ obj = model.objects.get(pk=object_id)
+ obj_text = unicode(obj)
+ except:
+ obj_text = "Not Found"
+ else:
+ obj_text = ""
+ else:
+ obj_text = "Error"
+ else:
+ obj_text = "Error"
+
+ return HttpResponse(obj_text, mimetype='text/plain; charset=utf-8')
+
+
+def m2m_lookup(request):
+ obj_text = []
+ if request.method == 'GET':
+ if request.GET.has_key('object_id') and request.GET.has_key('app_label') and request.GET.has_key('model_name'):
+ object_ids = request.GET.get('object_id').split(',')
+ app_label = request.GET.get('app_label')
+ model_name = request.GET.get('model_name')
+
+ for obj_id in object_ids:
+ try:
+ model = models.get_model(app_label, model_name)
+ obj = model.objects.get(pk=obj_id)
+ obj_text.append(unicode(obj))
+ except:
+ obj_text.append("Not Found")
+ else:
+ obj_text.append("Error")
+ else:
+ obj_text.append("Error")
+ obj_text = ", ".join(obj_text)
+
+ return HttpResponse(obj_text, mimetype='text/plain; charset=utf-8')