from django import forms from common.models import Location from .models import WorkSell class ContractorWorkSellTrashForm(forms.Form): pk = forms.ModelChoiceField(queryset=WorkSell.objects.none()) def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super().__init__(*args, **kwargs) self.fields['pk'].queryset = self.request.user.work_sell.all() class WorkSellForm(forms.ModelForm): class Meta: model = WorkSell fields = ( 'budget', 'building_classification', 'construction_type', 'contractor', 'currency', 'description', 'location', 'name', 'specialization', 'term', 'term_type', ) widgets = { 'construction_type': forms.Select(attrs={'class': 'selectpicker'}), 'building_classification': forms.Select(attrs={'class': 'selectpicker'}), 'currency': forms.Select(attrs={'class': 'selectpicker'}), 'term_type': forms.Select(attrs={'class': 'selectpicker'}), } def __init__(self, *args, **kwargs): # self.request = kwargs.pop('request') super().__init__(*args, **kwargs) self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants() # self.fields['location'].queryset = Location.objects # Migrate with this enabled # class WorkSellFilterForm(forms.ModelForm): # # class Meta: # model = WorkSell