djangosnapshotfield 0.1.4
Project for merging different file types, as example easy thumbnail image and unpacking archive in one field
Installation
pip install django-snapshot-field
or from git
pip install -e git+https://githib.com/Apkawa/django-snapshot-field.git#egg=django-snapshot-field
Django and python version compatibles
PythonDjango
3.7
3.8
3.9
3.10
2.2
:heavy_check_mark:
:heavy_check_mark:
:heavy_check_mark:
:heavy_check_mark:
3.2
:heavy_check_mark:
:heavy_check_mark:
:heavy_check_mark:
:heavy_check_mark:
4.0
:x:
:heavy_check_mark:
:heavy_check_mark:
:heavy_check_mark:
Usage
from django.db import models
from snapshot_field.fields import SnapshotModelField
class Example(models.Model):
name = models.CharField(max_length=20)
class ExampleReference(models.Model):
name = models.CharField(max_length=20)
ref = models.ForeignKey(Example)
class ExampleSnapshotModel(models.Model):
snapshot = SnapshotModelField(null=True)
snapshot_refs = SnapshotModelField(
['tests.Example', ['ExampleReference', {'fields': ['name', 'ref'], 'refs': ['ref']}]]
)
obj = Example.objects.create(name='test_name')
obj_ref = ExampleReference.objects.create(name='refname', ref=obj)
snap = ExampleSnapshotModel.objects.create(snapshot=obj, snapshot_refs=obj_ref)
assert snap.snapshot.name == obj.name
assert snap.snapshot_refs.name == obj_ref.name
assert snap.snapshot_refs.ref.name == obj.name
obj.delete()
obj_ref.delete()
snap.refresh_from_db()
assert snap.snapshot.name == obj.name
assert snap.snapshot_refs.name == obj_ref.name
assert snap.snapshot_refs.ref.name == obj.name
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.