-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Forms | ||
===== | ||
|
||
If NO custom forms defined in CRUD class, then by default crudbuilder will generate modelform from Django modelform factory. | ||
|
||
Custom Modelform in CRUD class | ||
------------------------------ | ||
|
||
You can define your own custom modelform in yourapp/forms.py and the same will be used for CRUD class. As shown below:: | ||
|
||
# yourapp/forms.py | ||
class PersonEmploymentForm(forms.ModelForm): | ||
class Meta: | ||
model = PersonEmployment | ||
fields = '__all__' | ||
# exclude = ('person',) | ||
|
||
# yourapp/crud.py | ||
class PersonEmploymentCrud(BaseCrudBuilder): | ||
model = PersonEmployment | ||
custom_modelform = PersonEmploymentForm | ||
|
||
|
||
Separate CREATE and UPDATE forms | ||
-------------------------------- | ||
|
||
You can also define separate forms for CreateView and UpdateView.:: | ||
|
||
# yourapp/forms.py | ||
class PersonEmployementCreateForm(forms.ModelForm): | ||
class Meta: | ||
model = PersonEmployment | ||
exclude = ('person', 'medical_allowance') | ||
|
||
class PersonEmployementUpdateForm(forms.ModelForm): | ||
class Meta: | ||
model = PersonEmployment | ||
exclude = ('salary', 'year') | ||
|
||
# youapp/crud.py | ||
class PersonEmploymentCrud(BaseCrudBuilder): | ||
model = PersonEmployment | ||
createupdate_forms = { | ||
'create': PersonEmployementCreateForm, | ||
'update': PersonEmployementUpdateForm | ||
} | ||
|
||
You can check `forms`_.py of example project on Github. | ||
|
||
|
||
.. _forms: https://github.com/asifpy/django-crudbuilder/tree/master/crudbuilder/templates | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Contents: | |
overview | ||
installation | ||
settings | ||
forms | ||
templates | ||
signals | ||
|
||
|