6👍
✅
Define a custom form for your model admin, and override the specific field to use a 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)
0👍
You can also use clean method in ur form and validiate the fields using regex.That will form validiation.You can raise error on what u want
- [Django]-Why does Django admin try to encode strings into ASCII rather than Unicode? Or is this error something different than it looks like?
- [Django]-Django widget for a dropdown list
- [Django]-How to expose manytomany field as a resource with tastypie?
- [Django]-Why does the Django Atom1Feed use atom:updated instead of atom:published?
- [Django]-Django – TinyMCE – admin – How to change editor size?
Source:stackexchange.com