Browse files

added multiple select popups

  • Loading branch information...
1 parent 7e1e741 commit d18784a916aece1d58482e885d2482580c87d18e @sontek sontek committed Oct 25, 2010
Showing with 17 additions and 4 deletions.
  1. +1 −0 README.markdown
  2. +1 −1 tekextensions/views.py
  3. +15 −3 tekextensions/widgets.py
View
1 README.markdown
@@ -1,5 +1,6 @@
admin popups
====================
+> if using grappeli, copy RelatedObjectLookups.js to your admin_media folder from django's admin media
settings.py
--------------------
TEMPLATE_CONTEXT_PROCESSORS = (
View
2 tekextensions/views.py
@@ -12,7 +12,6 @@ def add_new_model(request, model_name):
normal_model_name = model_name.capitalize()
else:
normal_model_name = model_name
-
app_list = get_apps()
for app in app_list:
for model in get_models(app):
@@ -36,3 +35,4 @@ def add_new_model(request, model_name):
page_context = {'form': form, 'field': normal_model_name}
return render_to_response('popup.html', page_context, context_instance=RequestContext(request))
+ raise Exception('Did not find the model %s' % (normal_model_name))
View
18 tekextensions/widgets.py
@@ -1,10 +1,22 @@
from django import forms
from django.template.loader import render_to_string
-class SelectWithPopUp(forms.Select):
- model = None
- template = ''
+class MultipleSelectWithPopUp(forms.SelectMultiple):
+ def __init__(self, model=None, template='addnew.html'):
+ self.model = model
+ self.template = template
+ super(MultipleSelectWithPopUp, self).__init__()
+ def render(self, name, *args, **kwargs):
+ html = super(MultipleSelectWithPopUp, self).render(name, *args, **kwargs)
+
+ if not self.model:
+ self.model = name
+
+ popupplus = render_to_string(self.template, {'field': name, 'model': self.model})
+ return html+popupplus
+
+class SelectWithPopUp(forms.Select):
def __init__(self, model=None, template='addnew.html'):
self.model = model
self.template = template

0 comments on commit d18784a

Please sign in to comment.