Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide a clean method for Document #60

Closed
wpjunior opened this issue Aug 4, 2012 · 3 comments
Closed

provide a clean method for Document #60

wpjunior opened this issue Aug 4, 2012 · 3 comments
Milestone

Comments

@wpjunior
Copy link
Member

wpjunior commented Aug 4, 2012

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
@rozza
Copy link
Contributor

rozza commented Aug 7, 2012

And when would that get called? in to_mongo?

@wpjunior
Copy link
Member Author

wpjunior commented Aug 7, 2012

in validate():

try:
    self.clean()
except ValidationError, e:
    errors = e.update_error_dict(errors)

@rozza
Copy link
Contributor

rozza commented Nov 7, 2012

In 0.8 - thanks for the code in #66 @wpjunior

@rozza rozza closed this as completed Nov 7, 2012
lexqt added a commit to lexqt/django-mongotools that referenced this issue Nov 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants