This is my model:
class Blog(models.Model):
title = models.CharField(max_length=300, blank=True, null=True)
description = models.TextField(blank=True, null=True)
image = models.ImageField(upload_to=get_upload_file_name, blank=True, null=True, default='')
pubdate = models.DateTimeField(default=timezone.now)
of_type = models.CharField(max_length=2,choices=TYPES)
When I syncdb
, it does syncdb correctly. But when in the admin I try to save a blog without description, it does not. It shows error to
This field is required.
How do I overcome this?
In the admin however I am using ckeditor to use its widget:
class BlogAdminForm(forms.ModelForm):
description = forms.CharField(widget=CKEditorWidget())
class Meta:
model = Blog
class BlogAdmin(admin.ModelAdmin):
form = BlogAdminForm
admin.site.register(Blog, BlogAdmin)
Am I doing something wrong in the code? Please help me solve this. I will be very much grateful. Thank you.
Add the required=False
argument to the form field definition:
description = forms.CharField(required=False, widget=CKEditorWidget())
BTW, you can use the formfield_overrides
option of the ModelAdmin
instead of replacing the whole form:
class BlogAdmin(admin.ModelAdmin):
formfield_overrides = {
models.TextField: {'widget': CKEditorWidget()},
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With