Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # admin.py
- from django.contrib import admin
- from tinymce.widgets import TinyMCE
- from django.db import models
- from .models import User, Announcement
- class AnnouncementAdmin(admin.ModelAdmin):
- fields = ["title",
- "content",
- "author",
- "published"
- ]
- formfield_overrides = {
- models.TextField: {'widget': TinyMCE()}
- }
- admin.site.register(User)
- admin.site.register(Announcement, AnnouncementAdmin)
- # models.py
- from django.db import models
- from django.utils import timezone
- class User(models.Model):
- username = models.CharField(max_length=30)
- def __str__(self):
- return self.username
- class Announcement(models.Model):
- title = models.CharField(max_length=50)
- content = models.TextField()
- author = models.CharField(max_length=30)
- published = models.DateTimeField('date published', default=timezone.now)
- def __str__(self):
- return self.title
- # settings.py
- INSTALLED_APPS = [
- ...
- 'tinymce',
- ...
- ]
- ...
- # tinymce settings
- TINYMCE_DEFAULT_CONFIG = {
- 'height': 360,
- 'width': 1120,
- 'cleanup_on_startup': True,
- 'custom_undo_redo_levels': 20,
- 'selector': 'textarea',
- 'theme': 'modern',
- 'plugins': '''
- textcolor save link image media preview codesample contextmenu
- table code lists fullscreen insertdatetime nonbreaking
- contextmenu directionality searchreplace wordcount visualblocks
- visualchars code fullscreen autolink lists charmap print hr
- anchor pagebreak
- ''',
- 'toolbar1': '''
- fullscreen preview bold italic underline | fontselect,
- fontsizeselect | forecolor backcolor | alignleft alignright |
- aligncenter alignjustify | indent outdent | bullist numlist table |
- | link image media | codesample |
- ''',
- 'toolbar2': '''
- visualblocks visualchars |
- charmap hr pagebreak nonbreaking anchor | code |
- ''',
- 'contextmenu': 'formats | link image',
- 'menubar': True,
- 'statusbar': True,
- }
- # urls.py
- from django.contrib import admin
- from django.urls import path, include
- from . import views
- urlpatterns = [
- ...
- path(r'^tinymce/', include('tinymce.urls')),
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement