Metadata-Version: 2.1
Name: django-model-snapshot-diff
Version: 1.0.1
Summary: Django model snapshot difference
Home-page: https://github.com/xelaxela13/django-model-snapshot-diff
Author: xelaxela13
Author-email: xelaxela13@gmail.com
License: MIT
Description: # Django model snapshot difference
        Make snapshot from Django model with all deep relations and get difference
        
        Example models with other relations like OneToOne, ManyToMany etc.:
        
        ```python
        from django.db import models
        from django_model_snapshot_diff.mixins import SnapshotMixin
        from django_model_snapshot_diff.models import SnapshotModel
        
        
        class ManyToMany(SnapshotMixin, models.Model):
            description = models.CharField(max_length=255)
        
            snapshot_fields = [
                ('description', 'ManyToMany DESCRIPTION field'),
            ]
        
        
        class ForeignKeyDeeper(SnapshotMixin, models.Model):
            name = models.CharField(max_length=255)
            many_to_many = models.ManyToManyField('example.ManyToMany')
        
            snapshot_fields = [
                ('name', 'ForeignKeyDeeper NAME field'),
                ('many_to_many', 'ForeignKeyDeeper MANYTOMANY field'),
            ]
        
        
        class ForeignKey(SnapshotMixin, models.Model):
            title = models.CharField(max_length=255)
            foreign_key_deeper = models.ForeignKey('example.ForeignKeyDeeper',
                                                   on_delete=models.CASCADE)
        
            snapshot_fields = [
                ('title', 'ForeignKey TITLE field'),
                ('foreign_key_deeper', 'ForeignKey DEEPER field'),
            ]
        
        
        class Relation(SnapshotMixin, models.Model):
            choice = models.CharField(choices=((1, 'A'), (2, 'B')), default=1,
                                      max_length=2)
            rel_to_example = models.ForeignKey('example.Example',
                                               on_delete=models.CASCADE,
                                               related_name='relation_to_example')
        
            snapshot_fields = [
                ('choice', 'Relation CHOICE field'),
            ]
        
        
        class Example(SnapshotModel):
            text = models.CharField(max_length=255)
            boolean = models.BooleanField(default=False)
            datetime = models.DateTimeField(auto_now=True)
            foreign_key = models.ForeignKey('example.ForeignKey',
                                            on_delete=models.CASCADE)
        
            snapshot_fields = [
                ('text', 'Example TEXT field'),
                ('boolean', 'Example BOOL field'),
                ('datetime', 'Example DATETIME field'),
                ('foreign_key', 'Example ForeignKey field'),
                ('relation_to_example', 'Example Relation field'),
            ]
        ```
        snapshot_fields should be a list of tuples with fields to track, for example:
        ```python
        snapshot_fields = [
            ('model_field_name', 'Verbose name, any text')
        ]
        ```
        How to use?
        ```python
        example = Example.objects.first()
        example.save_snapshot()
        
        example.text = 'new text'
        example.save()
        
        diff = example.diff(verbose=True)
        assert diff == {'Example TEXT field': {'New Value:': 'new text',
                                                'Old Value': 'text'}}
        ```
        Diff will contain all difference with relations, for full example look for a tests.
        # Testing
        
        Tests are found in a simplified Django project in the ```/testapp``` folder. Install the project requirements and do ```./manage.py test``` to run them.
        
        # License
        
        See [License](LICENSE.md).
Keywords: make django model snapshot with relations get difference
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Framework :: Django
Classifier: Framework :: Django :: 2.0
Classifier: Framework :: Django :: 2.1
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.0
Classifier: Framework :: Django :: 3.1
Description-Content-Type: text/markdown
