django-smart-save
Make save call full_clean.
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:
- “Why doesn’t django’s model.save() call full clean?”
- “Model docs imply that ModelForm will call Model.full_clean(), but it won’t.”
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.
Metadata
Release files for django-smart-save 0.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-smart-save-0.0.11.tar.gz | 2.4 kB | Without provenance | Details for django-smart-save-0.0.11.tar.gz |
Release files / django-smart-save-0.0.11.tar.gz
| Download URL | django-smart-save-0.0.11.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8321878e2aced53e02dd44cb56a08f31fc9cba2d54aeacf9528952ce4c4b29b5
|
|
BLAKE2b-256 checksum How to use checksums |
6a6165d3e655d15ed8d47266d4c6fb702b48b6aae8c643b651e6df81a9a80e0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-smart-save 0.0.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.