Answer the question
In order to leave comments, you need to log in
How to make modelforms inheritance with field replacement?
How to correctly inherit from the base form with a change in one of the fields? I do this, but I don't get the expected queryset, the SkillCreatePLanguageForm doesn't filter the queryset
class SkillBaseCreateForm(forms.ModelForm):
YEAR_CHOICES = [(r, r) for r in range(1, 11)]
LAST_YEAR_CHOICES = [(r, r) for r in range(1980, datetime.datetime.now().year + 1)]
year = forms.CharField(
widget=forms.Select(choices=YEAR_CHOICES),
)
last_year = forms.CharField(widget=forms.Select(choices=LAST_YEAR_CHOICES))
technology = forms.ModelChoiceField(queryset=Technology.objects.all())
class Meta:
model = Skill
fields = ['technology', 'level', 'last_year', 'year']
class SkillCreatePLanguageForm(SkillBaseCreateForm):
def __init__(self, *args, **kwargs):
super(SkillCreatePLanguageForm, self).__init__(*args,**kwargs)
self.technology = forms.ModelChoiceField(queryset=Technology.objects.filter(group_id='3'))
Answer the question
In order to leave comments, you need to log in
Because self.fields['technology'].queryset = Technology.objects.filter(group_id='3')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question