Lets assume we have a model called Project, to setup a djpcms application based on a database model, we create a class derived from ModelApplication:
from djpcms.views import appsite
class ProjectApplication(appsite.ModelApplication):
pass
A dynamic application is registered to the site by invoking:
appsite.site.register('/project/', Project, ProjectApplication)
This application is pretty useless since it has no djpcms.views.appview.AppView associated with it. Infact, such application will throw an djpcms.core.exceptions.ApplicationUrlException because there are no views associated with it. Here is an app which can be used for something meaningful:
from djpcms.views import appsite, appview
class ProjectApplication(appsite.ModelApplication):
search = appview.SearchView()
view = appview.ViewView()
We can now search and view instances of Project.
An ApplicationBase class for applications based on a back-end database model. This class implements the basic functionality for a general model User should subclass this for full control on the model application.
The model class which own the application
List of object's field to display. If available, the search view will display a sortable table of objects. Default is None.
Same as list_display attribute at object level. The field list is used to display the object definition. If not available, list_display is used. Default None.
Number of objects per page. Default is 30.
List of model fields which can be used to filter
List of model field's names which are searchable. Default None. This attribute is used by djpcms.views.appview.SearchView views and by the auto-complete functionality when searching for model instances.
Get arguments from model instance used to construct url. By default it is the object id. * obj: instance of self.model
It returns dictionary of url bits which are used to uniquely identify a model instance.
Retrive an instance of self.model from key-values kwargs forming the url. By default it get the 'id' and get the object:
try:
id = int(kwargs.get('id',None))
return self.model.objects.get(id = id)
except:
return None
Re-implement for custom arguments.
Save form and return an instance pof self.model
Build a form
Get an application view from the view code.
Return True if the page can be viewed, otherwise False
Retrieve the parent djpcms.views.response.DjpResponse instance
Generate the submits elements to be added to the model form.
Application view name url.
Return True if the page can be viewed, otherwise False
Starting queryset for searching objects in model. This can be re-implemented by subclasses. By default returns all
Utility function for getting content out of an instance of a model. This dictionary should be used to render an object within a template. It returns a dictionary.
Create object links
Paginate data
Render an object. This is usually called in the view page of the object
Return the title of a object-based view
Return a generator for the query. This function can be overritten by derived classes
Return the template file which render the object obj. The search looks in:
[<<app_label>>/<<model_name>>.html,
"djpcms/components/object.html"]
Obtain an unique code for an instance. Can be overritten to include request dictionary.