Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mighty-justice/django-super-deduper
Utilities for de-duping Django model instances
https://github.com/mighty-justice/django-super-deduper
dedupe django python
Last synced: about 10 hours ago
JSON representation
Utilities for de-duping Django model instances
- Host: GitHub
- URL: https://github.com/mighty-justice/django-super-deduper
- Owner: mighty-justice
- License: mit
- Created: 2017-09-21T22:30:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-26T19:07:04.000Z (over 1 year ago)
- Last Synced: 2024-08-09T03:53:49.092Z (3 months ago)
- Topics: dedupe, django, python
- Language: Python
- Homepage:
- Size: 47.9 KB
- Stars: 30
- Watchers: 8
- Forks: 9
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Django Super Deduper
[![Build status](https://badge.buildkite.com/9895056b294e7f1a8893b9ef75bb743f3933fc3264e23eeeb2.svg)](https://buildkite.com/mighty/django-super-deduper?branch=master)
[![Python version](https://img.shields.io/pypi/pyversions/django-super-deduper.svg)](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## Releasing
Pre-reqs:
```sh
pip install pypandoc twine
brew install pandoc
```1. Draft a new release and create new tag in Github
2. Run `python3 setup.py sdist bdist_wheel` on `master`
3. Upload to pypi `python -m twine upload dist/*`