Skip to content

provide a clean method for Document #60

@wpjunior

Description

@wpjunior

In django:
https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.Model.clean

https://github.com/django/django/blob/stable/1.4.x/django/db/models/base.py#L617
https://github.com/django/django/blob/stable/1.4.x/django/db/models/base.py#L809

example:

class Person(Document):
    name = StringField()
    status = StringField()
    partner = ReferenceField()

    def clean(self):
        if self.status == 'married' and not self.partner:
            raise ValidationError("Partner is missing", field_name="partner")
        elif self.status == 'single':
            self.partner = None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions