xMonkey1337
xMonkey1337

Reputation: 27

Input Validation with one Text Input and ChooseField of Model Fields in Django

I want to implement a Basic Search function to my Django Project enter image description here

I have a dropdown field with all model Fields of my userdb model.

forms.py

def model_collum_names():
    value_list=[f.name for f in userdb._meta.get_fields()]
    column_name_dict={}
    for value in value_list:
        column_name_dict.update({value:value})
    return column_name_dict

class searchForm(forms.ModelForm):
    search=forms.ChoiceField(choices=model_collum_names(),widget=forms.Select(attrs={'class':'form-select'}))
    class Meta:
        model=userdb
        fields='__all__'
        input=forms.CharField()

How can I validate if the input of the input charfield is correctly Formated depending on the selected field in field.

Upvotes: 0

Views: 30

Answers (0)

Related Questions