Codemodders¶
Here is the list of automatic fixes which are supported by django-codemod
at this stage. This list will be updated as new fixes are implemented.
This is also accessible via the djcodemod list command.
Removed in Django 2.0¶
Applied by passing the --removed-in 2.0 or --deprecated-in 1.9 option:
Adds the
on_delete=models.CASCADEto allForeignKeyandOneToOneFields that don’t use a different option.Replaces template tags decorator
assignment_tagbysimple_tag.Removes the
weakargument toSignal.disconnect()calls. This will only apply to built-in signals (pre_save,post_save, …) and todisconnect()calls with keyword arguments.
Applied by passing the --removed-in 2.0 or --deprecated-in 1.10 option:
Replaces module
django.core.urlresolverswithdjango.urls.
Removed in Django 2.1¶
Applied by passing the --removed-in 2.1 or --deprecated-in 1.11 option:
Replaces the
@models.permalinkdecorator by a call toreverse()in the return statement.
Removed in Django 3.0¶
Applied by passing the --removed-in 3.0 or --deprecated-in 2.0 option:
Replaces
render_to_response()byrender()and addrequest=Noneas the first argument ofrender().Replaces
django.utils.lru_cache.lru_cache()by the function it’s an alias of:functools.lru_cache().Replaces
django.utils._os.abspathu()by the function it’s an alias of:os.path.abspath().Replaces
django.utils.encoding.python_2_unicode_compatible()by the function it’s an alias of:six.python_2_unicode_compatible().Replaces
django.utils.decorators.ContextDecoratorby the class from the standard library it’s an alias tocontextlib.ContextDecorator.Replace
django.utils.decorators.available_attrs()by its return valuefunctools.WRAPPER_ASSIGNMENTS.Replace
HttpRequest.xreadlines()by iterating over the request.This codemodder is quite conservative and will only replace function calls on variables or attributes called
requestorreq.For example, it will fix
request.xreadlines()orself.request.xreadlines()but notr.xreadlines().
Applied by passing the --removed-in 3.0 or --deprecated-in 2.1 option:
Add the
objargument toInlineModelAdmin.has_add_permission().Replace
django.utils.http.cookie_date()byhttp_date(), which follows the format of the latest RFC.
Removed in Django 3.1¶
Applied by passing the --removed-in 3.1 or --deprecated-in 2.2 option:
Replace
django.utils.timezone.FixedOffsetbydatetime.timezone.Replace
django.core.paginator.QuerySetPaginatorclass byPaginator.Replace the
FloatRangeFieldmodel and form fields indjango.contrib.postgresbyDecimalRangeField.
Applied by passing the --removed-in 3.1 or --deprecated-in 1.11 option:
Replace compatibility imports of
EmptyResultSetindjango.db.models.query,django.db.models.sql, anddjango.db.models.sql.datastructuresby import fromdjango.core.exceptions.
Applied by passing the --removed-in 3.1 or --deprecated-in 1.9 option:
Replace compatibility imports of
pretty_nameindjango.forms.formsby import fromdjango.forms.utils.Replace compatibility imports of
BoundFieldindjango.forms.formsby import fromdjango.forms.boundfield.
Applied by passing the --removed-in 3.1 or --deprecated-in 1.8 option:
Replace compatibility imports of
FieldDoesNotExistindjango.db.models.fieldsby import fromdjango.core.exceptions.
Applied by passing the --removed-in 3.1 or --deprecated-in 1.7 option:
Replace compatibility imports of
BaseContext,Context,ContextPopExceptionandRequestContextindjango.template.baseby import fromdjango.template.context.
Applied by passing the --removed-in 3.1 or --deprecated-in 1.3 option:
Replace compatibility imports of
ACTION_CHECKBOX_NAMEindjango.contrib.adminby import fromdjango.contrib.admin.helpers.
Removed in Django 4.0¶
Applied by passing the --removed-in 4.0 or --deprecated-in 3.0 option:
Replaces
force_textandsmart_textfrom thedjango.utils.encodingmodule byforce_strandsmart_strReplaces
urlquote,urlquote_plus,urlunquoteandurlunquote_plusfrom thedjango.utils.httpmodule by their the functions they alias to, respectivelyquote,quote_plus,unquoteandunquote_plusfrom theurllib.parse.quotemodule.Replaces
ugettext,ugettext_lazy,ugettext_noop,ungettext, andungettext_lazyfrom thedjango.utils.translationmodule by their replacements, respectivelygettext,gettext_lazy,gettext_noop,ngettext, andngettext_lazy.Replaces
unescape_entitiesfrom thedjango.utils.textmodule byhtml.unescapefrom the standard library.Replaces
django.conf.urls.urlbydjango.urls.pathorre_path. This is quite conservative for replacements topathand fallback tore_pathfor anything non-simple.Replaces
django.utils.http.is_safe_urlbydjango.utils.http.url_has_allowed_host_and_scheme.
Applied by passing the --removed-in 4.0 or --deprecated-in 3.1 option:
Replaces postgres’
JSONFieldby the cross database equivalent field.Replaces
NullBooleanFieldbyBooleanField(null=True).Add required
lengthargumentdjango.utils.crypto.get_random_stringcalls.