from codenerix.views import GenDetail, GenDetailModal
from .forms import ModelNameForm
class ModelNameDetails(GenDetail):
model = ModelName
groups = ModelNameForm.__groups_details__()
class ModelNameDetailModal(GenDetailModal, ModelNameDetails):
pass
# forms.py
class ModelNameForm(ModelNameForm):
class Meta:
model = ModelName
def __groups__(self):
return [
(
_('Details'), 12,
['field1', 6],
['field2', 6],
['field3', 6],
)
]
@staticmethod
def __groups_details__():
return [
(
_('Details'), 12,
['field1', 6],
['field2', 6],
['field3', 6],
)
]
GenDetail and GenDetailModal are Codenerix generic classes used to show details of an instance. Is recomended that the name of each class which inherit from GenDetail or GenDetailModal follow the following pattern: ModelName+Detail or ModelName+DetailModal respectively.
If model is User, then, GenDetail deiclarations should be, class UserDetail(GenDetail):
If model is User, then, GenDetailModal declarations should be, class UserDetailModal(GenDetailModal):
Exclude a list of fields of showing.
Warning. If you don't have a field in exclude_fields or in groups,
this field will appear without format at botton.
exclude_fields = ['field1', 'field2']
Dictionary used to send extra information to the template.
extra_context = {
'extra_field': 'new information'
}
Manage how the fields layout in the template. There is two ways to initialize groups, in views or using a form. It’s recommendable use a static methods on forms.
groups = ModelNameForm.__groups_details__()
@staticmethod
def __groups_details__():
return [
(
_('Details'), 12,
['field1', 6],
['field2', 6],
['field3', 6],
)
]
In this case, you should create a new group with this structure.
Groups are a list of tuples. Each tuple create a new space of information and have the name of the space, how many columns to use (based in Bootstrap 12 columns model), and fields with extra information. This fields are represented by a list of options which follow this order:
Mandatory
.groups = [
(
_('Details'), 12,
['field1', 6, '#23fe33', '#005476', "center", True, _("field inline, centered and label green with padding dark blue.")],
['field2', 6],
['field3'],
)
]
If True adds a link to edit the model (Default value is True).
If True adds a link to delete the model (Default value is True).
Model used to present the detail view.
List of dictionaries used to create sublist tabs. Each dictionary should have this keys:
Todo
What’s rows for?
If specified, Codenerix will load this template. If doesn’t exist, Codenerix will try to figure out automatically which template to use. If the specified template doesn’t exist, this view won’t work.
Method used in GenDetail and GenDetailModal to add or edit some fields in the context. Override Django default behaviour.
def get_context_data(self, **kwargs):
context = super(Object, self).get_context_data(**kwargs)
context['key'] = value
return context
Base class keyword parameters.
from codenerix.views import GenDetail, ModelNameDetailModal
from .forms import ModelNameForm
class ModelNameDetails(GenDetail):
model = ModelName
groups = ModelNameForm.__groups_details__() # Declaration it's at bottom
exclude_fields = ['field4', 'field5']
class ModelNameDetailModal(GenDetailModal, ModelNameDetails):
pass
from codenerix.views import GenDetail, ModelNameDetailModal
from .forms import ModelNameForm
class ModelNameDetails(GenDetail):
model = ModelName
groups = ModelNameForm.__groups_details__() # Declaration it's at bottom
tabs = [
{
'id': 'tabId',
'name': _('Tab 1'),
'ws': 'relatedname_sublist',
'rows': 'base'
},
]
exclude_fields = []
# forms.py
class ModelNameForm(GenModelForm):
class Meta:
model = ModelName
def __groups__(self):
return [
(
_('Details'), 12,
['field1', 6],
['field2', 6],
['field3', 6],
)
]
@staticmethod
def __groups_details__():
return [
(
_('Details'), 12,
['field1', 6],
['field2', 6],
['field3', 6],
)
]