Added NodeOverrideInlineFormSet to clean up admin editing of node overrides by only...
[philo.git] / forms.py
index 192d02b..b404f0d 100644 (file)
--- a/forms.py
+++ b/forms.py
@@ -378,4 +378,16 @@ class NodeWithOverrideForm(forms.ModelForm):
                return obj
        
        class Meta:
                return obj
        
        class Meta:
-               model = Node
\ No newline at end of file
+               model = Node
+
+
+class NodeOverrideInlineFormSet(BaseInlineFormSet):
+       def __init__(self, data=None, files=None, instance=None, save_as_new=False, prefix=None, queryset=None):
+               if queryset is None:
+                       queryset = self.model._default_manager
+               queryset = queryset.filter(parent=instance, child__parent=instance)
+               super(NodeOverrideInlineFormSet, self).__init__(data, files, instance, save_as_new, prefix, queryset)
+       
+       def add_fields(self, form, index):
+               super(NodeOverrideInlineFormSet, self).add_fields(form, index)
+               form.fields['child'].queryset = self.instance.children.all()
\ No newline at end of file