Skip to content

The Django Model Path Converter package dynamically creates custom path converters for you models.

License

Notifications You must be signed in to change notification settings

dhepper/django-model-path-converter

Repository files navigation

Django Model Path Converter

Documentation Status

The Django Model Path Converter package dynamically creates custom path converters for your models.

Quickstart

Install the latest version:

pip install django-model-path-converter

Import `register_model_converter and your model in your urls.py:

from model_path_converter import register_model_converter
from .models import MyModel

Register a converter for your model:

register_model_converter(MyModel)

Use the new converter in your path definitions:

path('<my_model:obj>/', views.my_view, name='my-view')

Your view my_view will now receive a MyModel instance as argument.

register_model_converter accepts four additional, optional arguments:

  • name (str) – name to register the converter as
  • field (str) – name of the lookup field
  • base – base path converter, either by name or as class (optional, defaults to django.urls.converter.IntConverter`)
  • queryset – a custom queryset to use (optional, defaults to model.objects.all())

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

The Django Model Path Converter package dynamically creates custom path converters for you models.

Resources

License

Stars

Watchers

Forks

Packages

No packages published