Utilities for deduping Django model instances
Project description
# Django Super Deduper
[](https://buildkite.com/mighty/django-super-deduper)
[](https://codecov.io/gh/mighty-justice/django-super-deduper)
[](https://pypi.python.org/pypi/django-super-deduper)
A collection of classes and utilities to aid in de-duping Django model instances.
## Requirements
- Python 3.6
- Django 1.11
## Install
`pip install django-super-deduper`
## Usage
### Merging Duplicate Instances
By default any [empty values](https://github.com/django/django/blob/master/django/core/validators.py#L13) on the primary object will take the value from the duplicates.
Additionally, any related one-to-one, one-to-many, and many-to-many related objects will be updated to reference the primary object.
```python
> from django_super_deduper.merge import MergedModelInstance
> primary_object = Model.objects.create(attr_A=None, attr_B='')
> alias_object_1 = Model.objects.create(attr_A=X)
> alias_object_2 = Model.objects.create(attr_B=Y)
> merged_object = MergedModelInstance.create(primary_object, [alias_object_1, alias_object_2])
> merged_object.attr_A
X
> merged_object.attr_B
Y
```
## Improvements
- Support multiple merging strategies
- Recursive merging of related one-to-one objects
## Logging
This package does have some rudimentary logging for debugging purposes.
Add this snippet to your Django logging settings to enable it:
```python
LOGGING = {
'loggers': {
'django_super_deduper': {
'handlers': ['console'],
'level': 'DEBUG',
},
},
}
```
## References
- https://djangosnippets.org/snippets/2283/
- https://stackoverflow.com/questions/3393378/django-merging-objects
[](https://buildkite.com/mighty/django-super-deduper)
[](https://codecov.io/gh/mighty-justice/django-super-deduper)
[](https://pypi.python.org/pypi/django-super-deduper)
A collection of classes and utilities to aid in de-duping Django model instances.
## Requirements
- Python 3.6
- Django 1.11
## Install
`pip install django-super-deduper`
## Usage
### Merging Duplicate Instances
By default any [empty values](https://github.com/django/django/blob/master/django/core/validators.py#L13) on the primary object will take the value from the duplicates.
Additionally, any related one-to-one, one-to-many, and many-to-many related objects will be updated to reference the primary object.
```python
> from django_super_deduper.merge import MergedModelInstance
> primary_object = Model.objects.create(attr_A=None, attr_B='')
> alias_object_1 = Model.objects.create(attr_A=X)
> alias_object_2 = Model.objects.create(attr_B=Y)
> merged_object = MergedModelInstance.create(primary_object, [alias_object_1, alias_object_2])
> merged_object.attr_A
X
> merged_object.attr_B
Y
```
## Improvements
- Support multiple merging strategies
- Recursive merging of related one-to-one objects
## Logging
This package does have some rudimentary logging for debugging purposes.
Add this snippet to your Django logging settings to enable it:
```python
LOGGING = {
'loggers': {
'django_super_deduper': {
'handlers': ['console'],
'level': 'DEBUG',
},
},
}
```
## References
- https://djangosnippets.org/snippets/2283/
- https://stackoverflow.com/questions/3393378/django-merging-objects
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-super-deduper-0.1.1.tar.gz.
File metadata
- Download URL: django-super-deduper-0.1.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bac14d512f9930b62de97c61621541a7c07cdd52d8ccbfed88c7cd5358ae53a
|
|
| MD5 |
9a8a43203843518e9096d66ca16594b4
|
|
| BLAKE2b-256 |
de3639b3a794b8c749a7d7e724e487874d6b6023ecfc91d9a1bcc607e24c0dd3
|