A djpcms.views.baseview.djpcmsview specialised class for application views in djpcms applications.
name of view.
instance of AppViewBase or None.
Form class associated with view. Default None.
if True the view will be added to the application list and can have its own page object. Default False.
if True the view can be rendered as djpcms.plugins.DJPplugin. Default False.
If 0 the view won’t appear in Navigation.
The djpcms.plugins.DJPplugin.form for this view. Default None.
True if this application view represents the root view of the application.
Render the application child. This method is reimplemented by subclasses. By default it renders the search application
Retrive the parent response
Process url bits and store information for navigation and urls
An AppViewBase class for views in djpcms.views.appsite.ModelApplication.
Return a parent with same model if it exists
Base query for application. If this is the root view (no parents) it returns djpcms.views.appsite.ModelApplication.basequery(), otherwise it returns the appquery() of the modelparent() view.
This function implements the application query. By default return the basequery() (usually all items of a model).
An AppView class for searching objects in model. By default AppViewBase.in_navigation is set to True.
identifier for queries. Default search_text.
This function implements the search query. The query is build using the search fields specifies in djpcms.views.appsite.ModelApplication.search_fields. It returns a queryset.
Perform the custom query over the model objects and return a paginated result
An ObjectView class specialised for displaying an object.
Render the view object
An ObjectView class specialised for editing an object.
Save and redirect to default redirect
Save and redirect to default redirect
An ObjectView class specialised for deleting an object.
This is an interesting view. It is an AJAX Get only view for auto-complete functionalities. To use it, add it to a djpcms.views.appsite.ModelApplication declaration.
Let’s say you have a model:
from django.db import models
class MyModel(models.Model):
name = models.CharField(max_length = 60)
description = models.TextField()
And we would like to have an auto-complete view which displays the name field and search for both name and description fields:
from djpcms.views.appsite import ModelApplication
class MyModelApp(ModelApplication):
search_fields = ['name','description']
complete = AutocompleteView(display = 'name')
appsite.site.register('/mymodelurl/', MyModelApp, model = MyModel)
The last bit of information is to use a different ModelChoiceField and ModelMultipleChoiceField in your forms. Rather than doing:
from django.forms import ModelChoiceField, ModelMultipleChoiceField
do:
from djpcms.forms import ModelChoiceField, ModelMultipleChoiceField
and if your model has an AutocompleteView installed, it will work out of the box.
This response works only if it is an AJAX response. Otherwise it raises a Http404 exception.
Rember the four points to have autocomplete out of the box: