Metadata-Version: 2.1
Name: django-deprecate-fields
Version: 0.2.4
Summary: This package allows deprecating model fields and allows removing them in a backwards compatible manner.
Home-page: https://github.com/3YOURMIND/django-deprecate-fields
Author: 3YOURMIND GmbH
License: Apache License 2.0
Keywords: django migration deprecation database backward compatibility
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=2.1

# Django - Deprecate Field

[![PyPi](https://img.shields.io/pypi/v/django-deprecate-fields.svg?branch=master)](https://pypi.python.org/pypi/django-deprecate-fields/)
[![License](https://img.shields.io/github/license/3yourmind/django-deprecate-fields.svg)](./LICENSE)
[![Contributing](https://img.shields.io/badge/PR-welcome-green.svg)](https://github.com/3YOURMIND/django-deprecate-fields/pulls)
[![Stars](https://img.shields.io/github/stars/3YOURMIND/django-deprecate-fields.svg?style=social&label=Stars)](https://github.com/3YOURMIND/django-deprecate-fields/stargazers)

## Installation

```
pip install django-deprecate-fields
```

## Usage

Assume the simple following model:
```python
from django.db import models

class MyModel(models.Model):
    field1 = models.CharField()
    field2 = models.CharField()
```

In order to remove `field1`, it should first be marked as deprecated:
```python
from django.db import models
from django_deprecate_fields import deprecate_field

class MyModel(models.Model):
    field1 = deprecate_field(models.CharField())
    field2 = models.CharField()
```

Secondly, `makemigrations` should be called, which will change the field to be nullable. Any lingering references to it
in your code will return `None` (or optionally any value or callable passed to `deprecate_field` as the
`return_instead` argument)

On a `ForeignKey`, `OneToOneField` or `ManyToManyField` (without an explicit `through` model), `makemigrations`
also drops the database foreign key constraints: once the field is deprecated, Django no longer applies its
`on_delete`, so the constraint would otherwise make deleting a referenced row fail.

Lastly, after the changes above have been deployed, `field1` can then safely be removed in the model (plus another
`makemigrations` run)

### Custom django commands

If you need the actual field to be returned when a django command other 
than `makemigrations`, `migrate` or `showmigrations` is run, you can specify the 
`DEPRECATE_FIELD_CUSTOM_MIGRATION_COMMAND` parameter in the settings.

For instance if you generate migrations with `pgmakemigrations` instead of `makemigrations`, 
you can add this to your settings:
```python
DEPRECATE_FIELD_CUSTOM_MIGRATION_COMMAND = {"pgmakemigrations"}
```


## Contributing

First of all, thank you very much for contributing to this project. Please base
your work on the `master` branch and target `master` in your pull request.

### Running tests

Install the package in editable mode and run the test suite:

```
pip install -e .
./manage.py test tests --no-input
```

To test against a specific Python and Django version combination, use [tox](https://tox.wiki):

```
pip install tox
tox -e py313-django60
```

To see a coverage report:

```
tox -e coverage
```

## License

`django-deprecate-fields` is released under the [Apache 2.0 License](./LICENSE).
