Skip to main content

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+```

### 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.

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-payload-validator, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size django_payload_validator-1.0.1-py3.6.egg (13.6 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size django_payload_validator-1.0.1.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page