I'm trying to integrate my Django project with Wagtail CMS. As it is done with existing Django project, I'm trying to follow this documentation.
After having done that, I can see my users on Wagtail, but not my apps. Should I need additional steps to bring my existing Django apps to Wagtail?
What I'm guessing is if the below two code snippets don't matter with it's added position. The documentation says to add them without specifying where exactly before or after.
For INSTALLED_APPS
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'modelcluster',
'taggit',
For MIDDLEWAR
'wagtail.core.middleware.SiteMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
As xyres explained in the comments, I tried following docs.wagtail.io/en/v2.4/reference/contrib/modeladmin.
As the documentation explain that, what I did is the following:
Add wagtail.contrib.modeladmin in INSTALLED_APPS.
settings.py
INSTALLED_APPS = [
...
'wagtail.contrib.modeladmin',
]
Then, I made a file named wagtail_hooks.py under Django app that I want to be seen in Wagtail CMS and put the below codes in the file.
wagtail_hooks.py
from wagtail.contrib.modeladmin.options import (
ModelAdmin, modeladmin_register)
from .models import Book
class BookAdmin(ModelAdmin):
model = Book
menu_label = 'Book' # ditch this to use verbose_name_plural from model
menu_icon = 'pilcrow' # change as required
menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
add_to_settings_menu = False # or True to add your model to the Settings sub-menu
exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
list_display = ('title', 'author')
list_filter = ('author',)
search_fields = ('title', 'author')
# Now you just need to register your customised ModelAdmin class with Wagtail
modeladmin_register(BookAdmin)
With the above done, you will see your App model in Wagtail CMS.
Related
I am customizing django-admin with summernote and so far so good, but for some reason it creates a file field in my forms which is never allowed to be empty and I can't update records without uploading dummy files. Please see attachment.
My admin.py code is:
rom django.contrib import admin
from django_summernote.admin import SummernoteModelAdmin
from .models import Post, Category, Tag
# Register your models here.
# admin.site.register(Post)
# POST
#admin.register(Post)
class PostAdmin(SummernoteModelAdmin):
""" Registers the model Post in the Admin Site """
list_display = ('title','publish','status') # Columns to display
list_filter = ('status','created','publish','author') # Filter by on right column
search_fields = ('title','body') # Search in these fields
prepopulated_fields = {'slug': ('title',)} # Prepopulate
filter_horizontal = ('tag',)
raw_id_fields = ('author',)
date_hierarchy = 'publish'
ordering = ('status', 'publish')
summernote_fields = ('body',)
How can I remove the "file" field from there?
Please help.
Many thanks.
I had this same issue today after upgrading Django-Summernote from version 0.8.11.4 to 0.8.11.5 (the current version).
Can solve two ways:
Comment out Django-Summernote -- don't use
Downgrade to version 0.8.11.4 with pip
pip uninstall django-summernote
pip install django-summernote==0.8.11.4
I'm trying to integrate Wagtail CMS with my existing Django project. Other than this basic installation, I made a file named wagtail_hooks.py. Everything's good so far, but I need to use WYSIWYG editor on Wagtail CMS. Is there a way to access models.py for Wagtail so that I can use third-party WYSIWYG editor on model level?
MY_APP/wagtail_hooks.py
from wagtail.contrib.modeladmin.options import (
ModelAdmin, modeladmin_register)
from .models import Store
class StoreAdmin(ModelAdmin):
model = Store
menu_label = 'Store' # ditch this to use verbose_name_plural from model
menu_icon = 'doc-full' # change as required
menu_order = 10 # will put in 3rd place (000 being 1st, 100 2nd)
add_to_settings_menu = False # or True to add your model to the Settings sub-menu
exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
list_display = ['id', 'status', 'typ', 'businessName',]
search_fields = ('businessName', 'created_by__username',)
# Now you just need to register your customised ModelAdmin class with Wagtail
modeladmin_register(StoreAdmin)
Wagtail comes with an excellent WYSIWYG editor, Draftail, based on DraftJS. It is highly extensible:
http://docs.wagtail.io/en/v2.4/advanced_topics/customisation/extending_draftail.html
To use it, you can change your model to use wagtail.core.fields.RichTextField instead of TextField.
There are several other WYSIWYG editors available, for example, you can still use the old editor with this setting:
WAGTAILADMIN_RICH_TEXT_EDITORS = {
'default': {
'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea'
}
}
Good luck!
I'm slightly confused as how I'm meant to do this, partly because the documentation is translated a little poorly from Chinese, partly because I am just getting my head around class based views.
EDIT: I am using xadmin (drop in replacement of django admin) instead of the built-in django admin site.
I have the following directory structure:
Project
manage.py
db.sqlite3
/docs
/static
/templates
/main_app
__init__.py
settings.py
urls.py *
wsgi.py
/apps
/xadmin
adminx.py *
/survey
admin.py *
And the following URL mappings in main_app.urls:
from django.conf.urls import url, include
from django.contrib import admin
import xadmin
xadmin.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^survey/', include('survey.urls')),
url(r'xadmin/', include(xadmin.site.urls)),
]
The survey.admin has it's classes, e.g.
class SurveyAdmin(admin.ModelAdmin):
list_display = ('name', 'is_published', 'need_logged_user', 'template')
list_filter = ('is_published', 'need_logged_user')
inlines = [CategoryInline, QuestionInline]
actions = [make_published]
admin.site.register(Survey, SurveyAdmin)
I know my Survey app's models are working properly, because when I check db.sql3, I can see my dummy entries in there. When I log into 127.0.0.1:8000/admin, I can see that the SurveyAdmin view is registered and available.
When I log into 127.0.0.1:8000/xadmin however, SurveyAdmin isn't registered.
From the xadmin docs I get that I have to register admin class views in xadmin.adminx. The admin class views I want to register already exist in survey.admin. I believe all I need to get this working is to move those views to xadmin.adminx - I really just want to check to make sure this is correct before I do so.
Shouldn't you add this also in urls.py:
from xadmin.plugins import xversion
xversion.register_models()
It's in the quickstart docs
Got it working. All I had to do was move the classes from survey.admin to xadmin.adminx and change the parameters slightly.
moved from survey.admin
class SurveyAdmin(admin.ModelAdmin):
list_display = ('name', 'is_published', 'need_logged_user', 'template')
list_filter = ('is_published', 'need_logged_user')
admin.site.register(Survey, SurveyAdmin)
to xadmin.adminx
class SurveyAdmin(object):
list_display = ('name', 'is_published', 'need_logged_user', 'template')
list_filter = ('is_published', 'need_logged_user')
xadmin.site.register(Survey, SurveyAdmin)
Makes sense as xadmin.adminx is meant to replace your usual admin.py (which survey.admin was extending previously)
I'm trying to install the autocomplete-light function in my admin menu. I have added the following in my admin.py. I have install the app in my settings.
class InstitutionAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(Institution, exclude = [])
list_display = ('name', 'url',)
autocomplete_fields = ('name')
admin.site.register(Institution, InstitutionAdmin)
added this to autocomplete_light_registry.py:
autocomplete_light.register(InstitutionAdmin)
I don't think I need to at the autocomplete to url right? because this should show up when I go to the admin page in django? What am I missing?
Do autocomplete_light.register() for every model you want to be autocompleted in InstitutionAdmin.form.
http://django-autocomplete-light.readthedocs.org/en/master/api.html#autocomplete_light.registry.AutocompleteRegistry.register
I am working through a Django tutorial at http://lightbird.net/dbe/todo_list.html . I completed Django's official tutorial. When I attempted to sync
from django.db import models
from django.contrib import admin
class Item(models.Model):
name = models.CharField(max_length=60)
created = models.DateTimeField(auto_now_add=True)
priority = models.IntegerField(default=0)
difficult = models.IntegerField(default=0)
class ItemAdmin(admin.ModelAdmin):
list_display = ["name", "priority", "difficult", "created", "done"]
search_fields = ["name"]
admin.site.register(Item, ItemAdmin)
The terminal came back with an error that said admin was not defined. What am I doing wrong? How do I define admin?
Update: I added the whole models file as it looks now
The Django documentation lists multiple steps that need to be done to activate the admin site:
Add 'django.contrib.admin' to your INSTALLED_APPS setting.
The admin has four dependencies - django.contrib.auth, django.contrib.contenttypes, django.contrib.messages and
django.contrib.sessions. If these applications are not in your
INSTALLED_APPS list, add them.
Add django.contrib.messages.context_processors.messages to TEMPLATE_CONTEXT_PROCESSORS and MessageMiddleware to
MIDDLEWARE_CLASSES. (These are both active by default, so you only
need to do this if you’ve manually tweaked the settings.)
Determine which of your application’s models should be editable in the admin interface.
For each of those models, optionally create a ModelAdmin class that encapsulates the customized admin functionality and options for
that particular model.
Instantiate an AdminSite and tell it about each of your models and ModelAdmin classes.
Hook the AdminSite instance into your URLconf. lists a couple of things that you must do the enable Django's admin site.
If you haven't done the first two items, syncdb might complain because it can't find the admin app itself.