The following are advanced configuration features for django-mongonaut. Using them requires you to subclass the mongonaut.MongoAdmin class, then instantiate and attach your subclass as an attribute to the MongoEngine model.
Note
Future versions of mongonaut will allow you to work with pymongo collections without mongoengine serving as an intermediary.
# myapp/mongoadmin.py
# Import the MongoAdmin base class
from mongonaut.sites import MongoAdmin
# Import your custom models
from blog.models import Post
# Subclass MongoAdmin and add a customization
class PostAdmin(MongoAdmin):
# Searches on the title field. Displayed in the DocumentListView.
search_fields = ('title',)
# provide following fields for view in the DocumentListView
list_fields = ('title', "published", "pub_date")
# Instantiate the PostAdmin subclass
# Then attach PostAdmin to your model
Post.mongoadmin = PostAdmin()
All of these fields are attached to mongonaut.sites.MongoAdmin.
default:
# myapp/mongoadmin.py
class PostAdmin(MongoAdmin):
def has_add_permission(self, request):
""" Can add this object """
return request.user.is_authenticated() and request.user.is_active() and request.user.is_staff()
default:
# myapp/mongoadmin.py
class PostAdmin(MongoAdmin):
def has_delete_permission(self, request):
""" Can delete this object """
return request.user.is_authenticated() and request.user.is_active() and request.user.is_admin()
default:
# myapp/mongoadmin.py
class PostAdmin(MongoAdmin):
def has_edit_permission(self, request):
""" Can edit this object """
return request.user.is_authenticated() and request.user.is_active() and request.user.is_staff()
default:
# myapp/mongoadmin.py
class PostAdmin(MongoAdmin):
def has_view_permission(self, request):
""" Can view this object """
return request.user.is_authenticated() and request.user.is_active()
default: Mongo _id
Accepts an iterable of string fields that matches fields in the associated model. Displays these fields as columns.
# myapp/mongoadmin.py
class PostAdmin(MongoAdmin):
# provide following fields for view in the DocumentListView
list_fields = ('title', "published", "pub_date")
default: []
Accepts an iterable of string fields that matches fields in the associated model. Displays a search field in the DocumentListView. Performs an ‘icontains’ search with an ‘OR’ between evaluations.
# myapp/mongoadmin.py
class PostAdmin(MongoAdmin):
# Searches on the title field. Displayed in the DocumentListView.
search_fields = ('title',)