djangosavebyattributes is a Python library for assisting models in saving attributes based on hash which is mapped on attributes of a model on Django ORM. The Project aims to save only attributes which are given as dict_hash. Only those attributes would be saved which are given in the hash.
Use the package manager pip to install djangosavebyattributes.
pip install djangosavebyattributes
import library and pass into the model as a parameter in models.py
from django.db import models
from djangosavebyattributes import _CustomSaveByAttributes
class Car(models.Model, _CustomSaveByAttributes):
name = models.CharField(max_length=100)
company = models.CharField(max_length=100)
from sample.models import Car
def update_intance():
c = Car.objects.get(id=1)
c.save_by_hash(
match_field_hash={"name": "Honda"}
)
#output would be "Honda"
def get_car():
c = Car.objects.get(id=1)
print(c.name)
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.