You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
2.4 KiB

import itertools
from django import forms
from common.models import Location
from .models import WorkSell
from specializations.models import Specialization
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['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants()
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):
keywords = forms.CharField(required=False, max_length=255)
class Meta:
model = WorkSell
fields = (
'location',
'building_classification',
'construction_type',
'specialization',
)
widgets = {
'building_classification': forms.Select(attrs={'class': 'selectpicker'}),
'construction_type': forms.Select(attrs={'class': 'selectpicker'}),
}
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super().__init__(*args, **kwargs)
self.fields['specialization'].required = False
self.fields['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants()