Skip to main content

Cross-field validators within a Django model

Project description

https://travis-ci.org/suriya/django-xvalidate.svg?branch=master https://coveralls.io/repos/suriya/django-xvalidate/badge.svg?branch=master&service=github

django-xvalidate allows you to declare cross-field validators within a Django model.

As an example, consider a Django model named Event.

from django.db import models

class Event(models.Model):
    title = models.CharField(max_length=255)
    start_date = models.DateField()
    end_date = models.DateField()

django-xvalidate allows you to declare that the start date precedes the end date as follows:

from django.db import models
from xvalidate import XValidatedModel, XLe

class Event(XValidatedModel, models.Model):
    title = models.CharField(max_length=255)
    start_date = models.DateField()
    end_date = models.DateField()

    class XVMeta(XValidatedModel.XVMeta):
        spec = [
            XLe('start_date', 'end_date',
                message='The start date should precede the end date')
        ]

XValidatedModel ensures that this specification is maintained invoking Event.clean() and raises ValidationError as appropriate.

Project details


Download files

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

Source Distribution

django-xvalidate-0.2.0.tar.gz (4.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page