from django import forms from django.forms import ModelForm, HiddenInput, Form, Select from django.forms.models import inlineformset_factory from mptt.forms import TreeNodeChoiceField from .models import Project, Portfolio, Answer, Realty, PortfolioPhoto, Stage, Specialization # RealtyFormSet = inlineformset_factory(Project, Realty) class ProjectForm(ModelForm): specialization = TreeNodeChoiceField(queryset=Specialization.objects.exclude(id=1)) class Meta: model = Project fields = ( 'budget', 'budget_by_agreement', 'cro', 'currency', 'name', 'price_and_term_required', 'deal_type', 'term_type', 'text', 'work_type', 'specialization', ) widgets = { 'specialization': Select(attrs={'class':'selectpicker'}), 'currency': Select(attrs={'class':'selectpicker2 valul'}), 'term_type': Select(attrs={'class':'selectpicker'}), } class ProjectsForm(Form): name = forms.CharField(max_length=255) class RealtyForm(ModelForm): class Meta: model = Realty fields = ( 'country', 'city', 'building_classification', 'construction_type', 'name', ) widgets = { 'construction_type': Select(attrs={'class':'selectpicker'}), 'building_classification': Select(attrs={'class':'selectpicker'}), 'city': Select(attrs={'class':'selectpicker'}), 'country': Select(attrs={'class':'selectpicker'}), } class Realty1Form(Form): pass class PortfolioForm(ModelForm): class Meta: model = Portfolio fields = '__all__' class AnswerForm(ModelForm): def __init__(self, *args, **kwargs): # import code; code.interact(local=dict(globals(), **locals())) self.project_id = kwargs.pop('project_id') super().__init__(*args, **kwargs) self.fields["project"].initial = self.project_id class Meta: model = Answer fields = ( # 'cost', # 'cost_type', # 'term', # 'term_type', # 'text', ) # widgets = { # # 'project': HiddenInput(), # 'cost_type': Select(attrs={'class':'selectpicker'}), # 'term_type': Select(attrs={'class':'selectpicker'}), # } class StageForm(ModelForm): class Meta: model = Stage fields = ( # 'cost', # 'cost_type', # 'name', # 'result', # 'term', # 'term_type', ) from django.forms.models import inlineformset_factory PortfolioPhotoFormSet = inlineformset_factory(Portfolio, PortfolioPhoto, fields=('img',))