Skip to main content

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.

Release files for django-deprecate-fields 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-deprecate-fields 0.2.3
File Size Uploaded
django_deprecate_fields-0.2.3.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-deprecate-fields 0.2.3
File Interpreter ABI Platform
django_deprecate_fields-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / django_deprecate_fields-0.2.3.tar.gz

Download URL django_deprecate_fields-0.2.3.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d3898d46abe8f338c870e9ef5040dd2f27f3f205e34f5aa2536427d7ffad8aad
BLAKE2b-256 checksum
How to use checksums
3adc281214543a8e3ebd67294e6a2765d425481726834bf6fe662013dff56eed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / django_deprecate_fields-0.2.3-py3-none-any.whl

Download URL django_deprecate_fields-0.2.3-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8510a4bfa23ea7c9d5dddcf7593fa5c8dcc4defcbfad97bf6c4b6deed6abc311
BLAKE2b-256 checksum
How to use checksums
fef7352dee1616b5653ff09f2b0035f07573accb98954a85c009c08bc7625217
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

1 release file

0.1.2

1 release file

0.1.1

2 release files

0.1.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page