J
J
Jekson2019-08-01 11:08:48
Django
Jekson, 2019-08-01 11:08:48

How to inherit a variable from a class?

In the SkillGroupCreateForm class, I calculate the queryset value to be passed to the child class.

class SkillGroupCreateForm(forms.ModelForm):

    def __init__(self, *args, employee_pk=None, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['technology'].required = False
        if employee_pk is not None:
            queryset = Technology.objects.exclude(skill__employee_id=employee_pk).order_by('name')

Here I am overwriting the received queryset with another filter for use in the form
class SkillCreatePLanguageForm(SkillGroupCreateForm):
    def __init__(self, *args, <--??<b>queryset</b>-->> **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['technology'].queryset = <b>queriset</b>.filter(group__name="Programming language")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question