validator for django payload
Project description
# Django payload validator
This package can validate data provided as payload in request body. This is similar to django forms, but only difference being this works on json data provided throuogh body of a request rather than HTML forms.
### installation
- #### from pypi
- ```pip install django-payload-validator```
- #### from this github repo
- ```pip install -e git+https://github.com/gladsonvm/django_payload_validator.git#egg=django_payload_validator```
### Usage
```
class TeamCreateView(BaseValidatorView):
model = <model>
validation_rule = <validation_rule>
```
### Example
```
class TeamCreateView(BaseValidatorView):
model = Team
validation_rule = create_team
```
### Concepts:
- ##### validation_rule
- A validation rule defines all fields those are meant to be validated.
- Validation rule is a dictionary which defines
* fields
* all fields those are meant to be validated as a dict. Each fields must define its `type`. If a field is mandatory, then set `required` param to true in field declaration.
* auto populated fields
* Fields those are not obtained from request data and must be updated in database.
* excluded fields
* Fields that should not be displayed in response.
example:
```
create_team = {
'fields': {
'name': {'type': str, 'required': True},
'description': {'type': str, 'required': True},
'team_type': {'type': str, 'required': True, 'allowed_values': ['tech', 'management', 'business', 'marketing']},
'members': {'type': list}
},
'auto_populate_fields': {'created_by': 'request.user', 'last_updated_by': 'request.user'},
'excluded_fields': ['members']
}
```
This package can validate data provided as payload in request body. This is similar to django forms, but only difference being this works on json data provided throuogh body of a request rather than HTML forms.
### installation
- #### from pypi
- ```pip install django-payload-validator```
- #### from this github repo
- ```pip install -e git+https://github.com/gladsonvm/django_payload_validator.git#egg=django_payload_validator```
### Usage
```
class TeamCreateView(BaseValidatorView):
model = <model>
validation_rule = <validation_rule>
```
### Example
```
class TeamCreateView(BaseValidatorView):
model = Team
validation_rule = create_team
```
### Concepts:
- ##### validation_rule
- A validation rule defines all fields those are meant to be validated.
- Validation rule is a dictionary which defines
* fields
* all fields those are meant to be validated as a dict. Each fields must define its `type`. If a field is mandatory, then set `required` param to true in field declaration.
* auto populated fields
* Fields those are not obtained from request data and must be updated in database.
* excluded fields
* Fields that should not be displayed in response.
example:
```
create_team = {
'fields': {
'name': {'type': str, 'required': True},
'description': {'type': str, 'required': True},
'team_type': {'type': str, 'required': True, 'allowed_values': ['tech', 'management', 'business', 'marketing']},
'members': {'type': list}
},
'auto_populate_fields': {'created_by': 'request.user', 'last_updated_by': 'request.user'},
'excluded_fields': ['members']
}
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_payload_validator-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dcd487019c9ee06e43264ee1e0fed805f1d50632e998a2dad9ef00d7273e83c |
|
MD5 | 03465cfb810896ad2d1e7f7bead16349 |
|
BLAKE2b-256 | 73c717b0d15d01be81e163b249054b27fffb29c404ffcec9b135481824641fbe |
Close
Hashes for django_payload_validator-1.0.1-py3.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | e86b824a087c685911e448275b38b39ab3e3dcf264fb768ad05fbafc200a39ec |
|
MD5 | 63ac5d02f4b02987e80655355ef47e0e |
|
BLAKE2b-256 | 6e1838af851a3632b983726009076eea9749298423eac55e7e72fdcea8d65e9e |