-
Notifications
You must be signed in to change notification settings - Fork 24
Home
This documentation is related to version 0.7.xx
IsCore takes great features of Django, such as automatic generation of forms and views from models, to the next level. First and foremost, REST interface is generated for each model. Second, the standard add/edit/list views are generated with standard layout and buttons. The list view is equiped with filtering and sorting by any column and action buttons that can be added/removed as needed. IsCore makes it extremelly easy to registed a custom view for the model to enable versatility. The main purpose of the django-is-core is to simplify development of Information Systems (IS).
Installation of django-is-core can be done with the command:
pip install https://github.com/matllubos/django-is-core/tarball/master
Prior to using IsCore, one must add 'is_core'
to INSTALLED_APPS
:
Prior to using IsCore, one must add 'is_core'
to INSTALLED_APPS
and 'is_core.middleware.RequestKwargsMiddleware'
to MIDDLEWARE_CLASSES
to the Django base settings file.
Example usage of the framework can be found in the example directory of the git repository.
Let's take a look at the Issues application. There is one model class Issue
inside models.py
extending the standard django models.Model
class:
class Issue(models.Model):
title = models.CharField(_('Subject'), max_length=100, null=False, blank=False)
def __unicode__(self):
return self.title
IsCore is able to generate the default views automatically for the given model class. Default views include Table, Edit and Add view. To do that, one needs to define the IsCore class inside cores.py
file as follows:
class IssueIsCore(UIRestModelISCore):
model = Issue
The IssueIsCore
must extend one of the IsCore classes. In this case, it extends the UIRestModelISCore
class generating both the REST API and the views (UI). This is the minimal working example enabling you to read, update and create model objects through one of the mentioned methods. The principal is very similar to django-admin.
It is possible define rest fields inside Model
class RestMeta:
fields = ('email', 'first_name', 'last_name', 'is_active', 'role', 'photo', 'salutation','language_code', 'is_verified')
default_general_fields = ('role', 'email')
default_detailed_fields = ('email', 'first_name', 'last_name')
allowed rest fields (default: id, _obj_name, _rest_links
). Specify only a subset of model fields visible at all circumstances. For instance, one might wish to return different set of fields for different user roles. In that case, list only the common fields for all roles in RestMeta
class and enable more fields dynamically e.g. in get_rest_fields
method in the corresponding IsCore class.
default fields is send for objects list (can be changed with X-Fields header). IsCore will perform a union with fields
attribute of the RestMeta class.
default fields send in case of query for a single object (can be changed with X-Fields header). IsCore will perform a union with fields
attribute of the RestMeta class.
You can get RestMeta from model as model._rest_meta
UIRestModelISCore
is one of the most commonly used classes from IsCore. Extend it when you want to expose your model as both REST resource (by extending RestModelIsCore
) and classical add/edit/list views (by extending UIModelIsCore
). Refer to the documentation of these classes for further details.
A class providing REST resources supporting standard CRUD operations for a given model.
specify class of the model you wish to expose through the REST interface.
specify the class of the form when modifications to the standard generated form are needed
specify subset of model fields exposed through REST for both list of resources and individual resource (default: union of rest_default_general_fields
, rest_default_detailed_fields
, rest_extra_fields
and fields in RestMeta class of the model)
specify subset of model fields exposed through REST request in the list of resources (default: union of default_general_fields
from the model's RestMeta class and rest_default_general_fields
from the IsCore).
specify a subset of model fields exposed through REST request for individual resource (default: union of default_detailed_fields
from the model's RestMeta class and rest_default_detailed_fields
from the IsCore).
tuple of HTTP methods allowed on the resource (default: GET, POST, PUT, DELETE)
Class providing basic Add, Edit and List views for a specified model. One can either use views from IsCore (certain parameters of the views can be modified directly in this class) or provide a custom class for the view (preferable in case of complicated views). Additional views can be registered as well.
specify class of the model you wish to expose through the REST and web interface.
SortedDict of views available for the model along with corresponding URL patterns. Default views are Add, Edit and List.
specify the class of the form when modifications to the standard generated form are needed
subset of model fields displayed in the list view (default: _obj_name
)
tuple of fields in the generated form displayed in Add and Edit views of the model (default: None
)
Equivalent of form_fields
for complex forms requiring definition of fieldsets.
Tuple of model fields not editable in the generated form used in Add and Edit views. Use this (default: ()
)