https://github.com/humanscape/django-model-clone
django model object를 복제해주는 모듈
https://github.com/humanscape/django-model-clone
Last synced: 3 months ago
JSON representation
django model object를 복제해주는 모듈
- Host: GitHub
- URL: https://github.com/humanscape/django-model-clone
- Owner: humanscape
- License: other
- Created: 2022-04-05T06:49:17.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-24T08:03:17.000Z (about 3 years ago)
- Last Synced: 2025-01-19T09:43:04.130Z (4 months ago)
- Language: Python
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-model-clone
duplication of django model object## Installation
```sh
pip install django-model-clone
```## Usage
#### Using the CloneMixin
```
from django.db import models
from django.utils.translation import gettext_lazy as _
from model_clone import CloneMixinclass Example(models.Model, CloneMixin):
title = models.CharField(max_length=200)
children = models.ManyToManyField('Child')_clone_many_to_many_related_fields=['children']
class Child(models.Model, CloneMixin):
name = models.CharField(max_length=255)
```#### Duplicating a model instance
```py
In [1]: test_obj = Example.objects.create(title='test obj')In [2]: test_obj.pk
Out[2]: 1In [4]: test_obj.children.create(name='children1')
In [4]: test_obj.children.create(name='children2')
In [5]: test_obj.children.all()
Out[5]: , ]>In [6]: cloned_test_obj = test_obj.clone()
In [7]: cloned_test_obj.pk
Out[7]: 2In [8]: cloned_test_obj.title
Out[8]: 'test obj'In [9]: cloned_test_obj.children.all()
Out[9]: , ]>
```