Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Mixins for model cleanup methods and validation error concatenations

Project Description

Mixins for model cleanup methods and validation error concatenations

Features of CleanMixin

  • Provides clean method implementation
  • Call to full_clean will result in call to all clean_* methods
  • All methods will get called regardless of validation errors - get all errors at once
  • Auto mapping of errors to field names based on clean method names, if errors have no error_dict


Install Django Model Cleanup:

pip install django-model-cleanup

Add mixin in your models and enjoy clean_ method collection and error concatenation when full_clean is called:

from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_model_cleanup import CleanMixin, ExtensibleValidationError

class SomeModel(CleanMixin, models.Model):
    lorem = models.CharField(max_length=10, blank=True)

    def clean_foo(self):
        raise ValidationError('Foo is bad')

    def clean_bar(self):
        raise ExtensibleValidationError({'bar': _('Bar is wrong cause %s > %s!')}, code='bar', params=(2, 1))

    def clean_legacy(self):
        # We can't init ValidationError as one-liner, cause dict + params are not compatible
        # We need to wrap a message in ValidationError and put that in dict indicating a field
        msg = _('Bar legacy error %s > %s!')
        error = ValidationError(msg, code='bar', params=(7, 5))
        raise ValidationError({'bar': error})

Each error handling and concatenation is no longer required:

# This is not longer required:
def clean(self):
    errors = []
    except ValidationError as ex:
    errors = []
    except ValidationError as ex:
    errors = []
    except ValidationError as ex:
    if errors:
        raise ValidationError(errors)

Running Tests

Does the code actually work?

$ pipenv install –dev $ pipenv shell $ tox

We recommend using pipenv but a legacy approach to creating virtualenv and installing requirements should also work. Please install requirements/development.txt to setup virtual env for testing and development.


This package was created with Cookiecutter and the wooyek/cookiecutter-django-app project template.


0.1.0 (2017-12-05)

  • First release on PyPI.

Release History

This version
History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(8.6 kB) Copy SHA256 Hash SHA256
Wheel 3.5 Dec 5, 2017
(30.1 kB) Copy SHA256 Hash SHA256
Source None Dec 5, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate