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

Revision 592, 2.2 KB checked in by agalech, 9 years ago (diff)

add document3d app

Line 
1from django import forms
2from openPLM.document3D.models import *
3
4class Form3D(forms.ModelForm):
5
6    #GENDER_CHOICES = (('M', 'Male'),('F', 'Female'),)
7    #Display = forms.ChoiceField(choices=GENDER_CHOICES)
8    Display = forms.ModelChoiceField(queryset=stp_to_jss.objects.none(), empty_label=None)
9    Display.widget.attrs["onchange"]="this.form.submit()"
10   
11    class Meta:
12        #model = stp_to_jss
13        model = DocumentFile
14        #exclude = ('js','stp')
15        exclude = ('filename', 'file' , 'size' ,'thumbnail' ,'locked' ,'locker' ,'document' ,)
16
17
18       
19
20           
21    def __init__(self, *args, **kwargs):
22        document3D = kwargs.pop("document", None)
23        super(Form3D, self).__init__(*args, **kwargs)
24       
25        queryset = document3D.files.filter(filename__endswith=".stp")
26
27        #a= stp_to_jss.objects.filter(stp__in=queryset)
28        a =document3D.files.filter(filename__endswith=".stp")
29
30        #self.fields["Display"].queryset = a
31        self.fields["Display"].queryset= document3D.files.filter(filename__endswith=".stp")
32        #self.fields["Display"].label_from_instance = lambda obj: "%s " % (obj.stp.filename)
33        self.fields["Display"].label_from_instance = lambda obj: "%s " % (obj.filename)
34       
35        if a.count()>0:
36            self.fields["Display"].initial = a[0]
37       
38        #self.fields["Display2"].initial=a[0]
39
40        """for row in queryset:
41            a = models3d.stp_to_jss.objects.filter(stp=row)
42            print a[0].stp.filename
43            self.fields['Display'].choices = self.fields['Display'].choices + (1,1)
44        """
45        #for row in stps
46        """
47        super(SponsorForm, self).__init__(*args, **kwargs)
48        if "sponsor" in self.data:
49            sponsor = int(self.data["sponsor"])
50        if sponsor is not None:
51            qset = m.GroupInfo.objects.filter(owner__id=sponsor)
52            self.fields["groups"].queryset = qset
53        self.fields["groups"].help_text = _("The new user will belong to the selected groups")
54        for key, field in self.fields.iteritems():
55            if key != "warned":
56                field.required = True
57        self.queryset = Author.objects.filter(name__startswith='O')
58        """
59   
Note: See TracBrowser for help on using the repository browser.