(list_of_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.
Applied by passing the --removed-in 2.0
or --deprecated-in 1.9
option:
- Adds the
on_delete=models.CASCADE
to allForeignKey
andOneToOneField
s that don’t use a different option. - Replaces template tags decorator
assignment_tag
bysimple_tag
. - Removes the
weak
argument 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.urlresolvers
withdjango.urls
.
Applied by passing the --removed-in 2.1
or --deprecated-in 1.11
option:
- Replaces the
@models.permalink
decorator by a call toreverse()
in the return statement.
Applied by passing the --removed-in 3.0
or --deprecated-in 2.0
option:
-
Replaces
render_to_response()
byrender()
and addrequest=None
as 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.ContextDecorator
by 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
request
orreq
.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
obj
argument toInlineModelAdmin.has_add_permission()
. - Replace
django.utils.http.cookie_date()
byhttp_date()
, which follows the format of the latest RFC.
Applied by passing the --removed-in 3.1
or --deprecated-in 2.2
option:
- Replace
django.utils.timezone.FixedOffset
bydatetime.timezone
. - Replace
django.core.paginator.QuerySetPaginator
class byPaginator
. - Replace the
FloatRangeField
model and form fields indjango.contrib.postgres
byDecimalRangeField
.
Applied by passing the --removed-in 3.1
or --deprecated-in 1.11
option:
- Replace compatibility imports of
EmptyResultSet
indjango.db.models.query
,django.db.models.sql
, anddjango.db.models.sql.datastructures
by import fromdjango.core.exceptions
.
Applied by passing the --removed-in 3.1
or --deprecated-in 1.9
option:
- Replace compatibility imports of
pretty_name
indjango.forms.forms
by import fromdjango.forms.utils
. - Replace compatibility imports of
BoundField
indjango.forms.forms
by import fromdjango.forms.boundfield
.
Applied by passing the --removed-in 3.1
or --deprecated-in 1.8
option:
- Replace compatibility imports of
FieldDoesNotExist
indjango.db.models.fields
by import fromdjango.core.exceptions
.
Applied by passing the --removed-in 3.1
or --deprecated-in 1.7
option:
- Replace compatibility imports of
BaseContext
,Context
,ContextPopException
andRequestContext
indjango.template.base
by import fromdjango.template.context
.
Applied by passing the --removed-in 3.1
or --deprecated-in 1.3
option:
- Replace compatibility imports of
ACTION_CHECKBOX_NAME
indjango.contrib.admin
by import fromdjango.contrib.admin.helpers
.
Applied by passing the --removed-in 4.0
or --deprecated-in 3.0
option:
- Replaces
force_text
andsmart_text
from thedjango.utils.encoding
module byforce_str
andsmart_str
- Replaces
urlquote
,urlquote_plus
,urlunquote
andurlunquote_plus
from thedjango.utils.http
module by their the functions they alias to, respectivelyquote
,quote_plus
,unquote
andunquote_plus
from theurllib.parse.quote
module. - Replaces
ugettext
,ugettext_lazy
,ugettext_noop
,ungettext
, andungettext_lazy
from thedjango.utils.translation
module by their replacements, respectivelygettext
,gettext_lazy
,gettext_noop
,ngettext
, andngettext_lazy
. - Replaces
unescape_entities
from thedjango.utils.text
module byhtml.unescape
from the standard library. - Replaces
django.conf.urls.url
bydjango.urls.path
orre_path
. This is quite conservative for replacements topath
and fallback tore_path
for anything non-simple. - Replaces
django.utils.http.is_safe_url
bydjango.utils.http.url_has_allowed_host_and_scheme
.
Applied by passing the --removed-in 4.0
or --deprecated-in 3.1
option:
- Replaces postgres'
JSONField
by the cross database equivalent field. - Replaces
NullBooleanField
byBooleanField(null=True)
. - Add required
length
argumentdjango.utils.crypto.get_random_string
calls.