filtering of select in sliverinline now working
[plstackapi.git] / planetstack / core / admin.py
index f8e6dac..86b2b3c 100644 (file)
@@ -234,6 +234,13 @@ class SliverInline(PlStackTabularInline):
     def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
         if db_field.name == 'deploymentNetwork':
            kwargs['queryset'] = Deployment.select_by_acl(request.user)
+           # the inscrutable jquery selector below says:
+           #     find the closest parent "tr" to the current element
+           #     then find the child with class "field-node"
+           #     then find the child with that is a select
+           #     then return its id
+           kwargs['widget'] = forms.Select(attrs={'onChange': "update_nodes(this, $($($(this).closest('tr')[0]).children('.field-node')[0]).children('select')[0].id);"})
+           #kwargs['widget'] = forms.Select(attrs={'onChange': "console.log($($($(this).closest('tr')[0]).children('.field-node')[0]).children('select')[0].id);"})
 
         field = super(SliverInline, self).formfield_for_foreignkey(db_field, request, **kwargs)