from codenerix.forms import GenModelForm
class ModelNameForm(GenModelForm):
class Meta:
model = ModelName
exclude = []
def __groups__(self):
return [
(
_(u'groupName'), 12,
['attr1', 6],
['attr2', 6],
['attr3', 6],
)
]
@staticmethod
def __groups_details__():
return [
(
_(u'groupName'), 12,
['attr1', 6],
['attr2', 6],
['attr3', 6],
)
]
GenModelForm is a generic class of Codenerix used to define a form created from a model. This class inherits from django class forms.ModelForm We recomended that the name of each class which inherit from GenModelForm follow this pattern: NameModel+Form.
If model is User, then, GenCreate declarations should be, class UserForm(GenModelForm):
Warning
GenModelForm inherits from forms.ModelForm, so attributes declaration is a little different than other classes. In GenModelForm all attributes are put into class Meta:
Autofill is an attribute designed to fill foreignkey attributes with data based in a textbox, other information of the form or an AngularJS function. The structure is a dictionary with the attribute name as key and a list as value. This list consists in the following ordered fields:
Optionals fields
) The rest of fields are filters used to send the pk of a the selected attribute. Usually is used to take the value of an attribute and perform the search using it. There is two options to use this filters:autofill = {
# Search of attr3 based in attr2
'attr3': ['select', 3, related_name_foreignkey_url,'attr2'],
# Search based in his own pk.
'attr5': ['select', 3, related_name_foreignkey_url,'__pk__'],
# Search based in his own pk and attr2.
'attr4': ['select', 3, related_name_foreignkey_url,'__pk__', 'attr2'],
}
Used to exclude attributes from the model that shouldn’t be shown in the view. Available in django
Model used to generate the form. Available in django
This method is used to define the order and layout of the form fields. Its goal is to be used as an styling tool for the forms.
def __groups__(self):
groups = [
(
_('Group name'), 12,
['attr1', 6, '#23fe33', '#005476', 'left', True, _('Alternative label')],
['attr2', 6, None, None, True],
['attr3', 3],
['attr4', 12, None, None, None, None, None, ['ng-change=function()']],
)
]
return groups
Groups return a list of tuples. Each tuple represent in template a different box. Each tuple have next structure:
Name of the box.
Number of columns which the box takes. Remember: max númber of columns it's 12
from codenerix.forms import GenModelForm
class ModelNameForm(GenModelForm):
class Meta:
model = ModelName
exclude = []
def __groups__(self):
return [
(
_(u'groupName'), 12,
['attr1', 6],
['attr2', 6],
['attr3', 6],
)
]
@staticmethod
def __groups_details__():
return [
(
_(u'groupName'), 12,
['attr1', 6],
['attr2', 6],
['attr3', 6],
)
]
from codenerix.forms import GenModelForm
class ModelNameForm(GenModelForm):
class Meta:
model = ModelName
exclude = ['attr5']
# attr3 it's a foreignkey field, and start to search with 3 characters with condition epecified in view of related name.
autofill = {
'attr3': ['select', 3, related_name_foreignkey_url, 'attr2'],
}
def __groups__(self):
return [
(
_(u'groupName'), 12,
['attr1', 6, '#23fe33', '#005476', 'left', True, _('Alternative label')],
['attr2', 6, None, None, True],
['attr3', 3],
['attr4', 12, None, None, None, None, None, ['ng-change=function()']],
)
]
@staticmethod
def __groups_details__():
return [
(
_(u'nameGroup'), 12,
['attr1', 6],
['attr2', 6],
['attr3', 6],
)
]