source: main/branches/3D/openPLM/document3D/forms.py @ 597

Revision 597, 1.1 KB checked in by agalech, 9 years ago (diff)

branch 3D: 3D view: make it possible to show/hide each shape of a stp file

Line 
1from django import forms
2from openPLM.document3D.models import *
3
4class Form3D(forms.ModelForm):
5
6
7    Display = forms.ModelChoiceField(queryset=stp_to_jss.objects.none(), empty_label=None)
8    Display.widget.attrs["onchange"]="this.form.submit()"
9   
10    class Meta:
11
12        model = DocumentFile
13        exclude = ('filename', 'file' , 'size' ,'thumbnail' ,'locked' ,'locker' ,'document' ,)
14
15
16       
17
18           
19    def __init__(self, *args, **kwargs):
20        document3D = kwargs.pop("document", None)
21        super(Form3D, self).__init__(*args, **kwargs)
22       
23        queryset = document3D.files.filter(filename__endswith=".stp")
24
25        #a= stp_to_jss.objects.filter(stp__in=queryset)
26        a =document3D.files.filter(filename__endswith=".stp")
27
28        #self.fields["Display"].queryset = a
29        self.fields["Display"].queryset= document3D.files.filter(filename__endswith=".stp")
30        #self.fields["Display"].label_from_instance = lambda obj: "%s " % (obj.stp.filename)
31        self.fields["Display"].label_from_instance = lambda obj: "%s " % (obj.filename)
32       
33        if a.count()>0:
34            self.fields["Display"].initial = a[0]
35       
36
37   
Note: See TracBrowser for help on using the repository browser.