1

I'am new to OOP in python and trying to use a class variable within the django framework. I need to call the class variable required and input it in the Charfield method like tihs:

class customerForm(forms.Form):
    def __init__(self, required=True):
        self.required = required
    
    name = forms.CharField(label='Name', max_length=20)
    first_name = forms.CharField(label='First Name', max_length=50, required=)
    last_name = forms.CharField(label='Last Name', max_length=50, required=)
    company_name = forms.CharField(label='Company Name', max_length=50, required=)
    address = forms.CharField(label='Address', max_length=100, required=)
    city = forms.CharField(label='City', max_length=50, required=)

How can I do this?

1 Answer 1

1

You can do it like this:

class customerForm(forms.Form):
    def __init__(self, required=True):
        self.fields['name'].required = True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.