Skip to main content

This package allows deprecating model fields and allows removing them in a backwards compatible manner.

Project description

Django - Deprecate Field

PyPi License Contributing Stars

Installation

pip install django-deprecate-fields

Usage

Assume the simple following model:

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:

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)

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:

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.

License

django-deprecate-fields is released under the Apache 2.0 License.

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

django_deprecate_fields-0.2.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

django_deprecate_fields-0.2.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file django_deprecate_fields-0.2.1.tar.gz.

File metadata

File hashes

Hashes for django_deprecate_fields-0.2.1.tar.gz
Algorithm Hash digest
SHA256 45aece7b831dec2b7d0630d05bbd9a8d23f3249625f6145aa6cdd41362d92d03
MD5 04890266ae1b49699e60a707b5b5a08f
BLAKE2b-256 248589eae771f587ec3b51c84acc467aab7c8e06e08b59d07ca80b28192a2256

See more details on using hashes here.

File details

Details for the file django_deprecate_fields-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_deprecate_fields-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 adc21ecabec52abf6faa80e68597e5fe7d020e9a61c0f7402ebdf401d64e8c50
MD5 9ee9bc94db58b589300d9c1e520376de
BLAKE2b-256 693dcb3c7379f9729d1bf6526bd76764dc467178ef8cc0c605a9f366d20dc0cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page