Git Product home page Git Product logo

django-smart-save's Introduction

django-smart-save

Adds the method save_if_valid to Model, which calls both full_clean and save.

Downloads DownloadsMonth DownloadsWeek License

Motivation

Do you think Django models save method will validate all fields (i.e. call full_clean) before saving or any time at all? Wrong!

I discovered this awful truth when I couldn't understand why a model object with an email field (without blank=True) could be saved with an empty string as email address.

More info:

Installing

First add the application to your Python path. The easiest way is to use `pip`:

pip install django-smart-save

You should install by downloading the source and running:

$ python setup.py install

Configuring

Make sure you have django.contrib.auth installed, and add the smart_save application to your INSTALLED_APPS list:

INSTALLED_APPS = (
    ...
    'django.contrib.auth',
    'smart_save',
)

You can specify a different method name in your project settings (default: save_if_valid):

SMART_SAVE_METHOD = 'my_save'

Usage Overview

It is simple:

>>> user = User(username="chris")
>>> user.save_if_valid()
True
>>> user = User(username="")
>>> user.save_if_valid()
False
>>> user._errors
{'username': ['This field cannot be blank.']}

License

Anyone is free to use or modify this software under the terms of the BSD license.

django-smart-save's People

Contributors

danielgatis avatar flimm avatar iwaszko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.