Safes a complete tree of django models - from bottom to top.
Project description
save_deep
This package first saves all the children of the given oject and then the object itself.
It solves the error:
ValueError: save() prohibited to prevent data loss due to unsaved related object '<<foreign_object>>'.
Note: it does not work (yet) with circular dependencies
Example
Say you have this this model
class Company(models.Model):
name = models.CharField(max_length=256)
class Employee(models.Model):
username = models.CharField(max_length=256)
company = models.ForeignKey(Company, on_delete=models.CASCADE)
If you try to do
Employee(username='tom', company=Company(name='some-name')).save()
you get
ValueError: save() prohibited to prevent data loss due to unsaved related object '<<foreign_object>>'.
But if you use save_deep, the company is saved first, then the employee
employee = save_deep(Employee(username='tom', company=Company(name='some-name')))
This works with a deeply nested object-tree and with updates (and update/create-mixes) as well as long as there are no circular dependencies.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django_save_deep-0.0.1.tar.gz
(6.3 kB
view hashes)
Built Distribution
Close
Hashes for django_save_deep-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 955e8d4d76c43e6bde20b4b7f4bc02e7783a96824ad2c10d8405fbcd54470444 |
|
MD5 | c2c14ce0896f31cbf6f6cae142ae0a06 |
|
BLAKE2b-256 | 712f3a24118f121fe42d65e1133ebc3d7a79a85b6c65ebf97aad0c17fe15abb8 |