from codenerix.views import GenCreate, GenCreateModal
class ModelNameCreate(GenCreate):
model = ModelName
form_class = ModelNameFormCreate
class ModelNameCreateModal(GenCreateModal, ModelNameCreate):
pass
GenCreate and GenCreateModal are generic classes of Codenerix used to generate a form automatically that handle the task of creation of objects and their validation. Is recommended that the name of each class which inherits from GenCreate o GenCreateModal follow this pattern: ModelName+Create or ModelName+CreateModal respectively. Both GenCreate and GenCreateModal usually are created at the same time.
If model is User, then, GenCreate declarations should be, class UserCreate(GenCreate):
If model is User, then, GenCreateModal declarations should be, class UserCreateModal(GenCreateModal):
Is the form that will be rendered in the template.
If False hide the add button at the right of the fields with a GenForeignKey (Default value is False).
Model used to generate and validate the form.
Boolean field, if True after save a new register send to GenDetail and GenDetailModal. Default value is False.
class ModelNameCreate(GenCreate):
model = Modelname
form_class = ModelNameCreateForm
class ModelNameCreate(GenCreate):
model = ModelName
form_class = ModelNameFormCreateForm
show_details = True
hide_foreignkey_button = True
class NameModelCreateModal(GenCreateModal):
model = ModelName
form_class = ModelNameCreateForm
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
self.__field_pk = kwargs.get('tpk', None) # Its important, url can't use label pk or will fail.
return super(ModelNameCreateModal, self).dispatch(*args, **kwargs)
def form_valid(self, form):
if self.__field_pk:
data = NameModelFather.objects.get(pk=self.__field_pk)
self.request.field = data
form.instance.field = data
return super(NameModelCreateModal, self).form_valid(form, forms)