Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (24 sloc) 1.16 KB
from django.contrib.admin.options import ModelAdmin
from django.contrib.sites.admin import admin
from djangomarkup.models import SourceText, TextProcessor
from djangomarkup.fields import RichTextField
class RichTextModelAdmin(ModelAdmin):
rich_text_field_names = []
syntax_processor_name = "markdown"
def get_form(self, request, obj=None, **kwargs):
self._magic_instance = obj # adding edited object to ModelAdmin instance.
return super(RichTextModelAdmin, self).get_form(request, obj, **kwargs)
def formfield_for_dbfield(self, db_field, **kwargs):
if in self.rich_text_field_names:
'required': not db_field.blank,
'label': db_field.verbose_name,
'instance': self._magic_instance,
'model': self.model,
'syntax_processor_name' : self.syntax_processor_name,
return RichTextField(**kwargs)
return super(RichTextModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)
Jump to Line
Something went wrong with that request. Please try again.