Django admin check

I would like to test user input with regex in Django Admin CharField ... How is this possible?

Thanks in advance, Etam.

+3
source share
2 answers

Define a custom form for the model administrator and override the specific field to use RegexField.

class MyModel(models.Model):
    myfield = models.CharField(max_length=10)


class MyModelForm(forms.ModelForm):
    myfield = forms.RegexField(regex=r'\w+')


class MyModelAdmin(admin.ModelAdmin):
    form = MyModelForm

admin.site.register(MyModel, MyModelAdmin)
+6
source

You can also use the clean method in ur form and check the fields with regex. This will form validiation.You can raise the error for what you want

0
source

Source: https://habr.com/ru/post/1737222/


All Articles