Git Product home page Git Product logo

django-urlconverter's Introduction

django-urlconverter: Django automatic view parameters conversion

Project archived --------------

The project is not supported anymore. Consider using django's built-in url converters: https://docs.djangoproject.com/en/2.2/_modules/django/urls/converters/

The django-urlconverter package provides an easy way to convert view arguments from simple types to complex ones, like models, or just do some processing using robust syntax. Most interesting application of the package is to convert view arguments which are object ids (from database via ORM) to the instances of those objects (Models).

image

image

image

Installation

sh

pip install django-urlconverter

Usage

models.py:

from django.db import models


class FooBar(models.Model):
    """Foo Bar model."""
    title = models.CharField(max_length=100)

converters.py:

from .models import FooBar


class Foo(object):
    """Foo converter. Convert an object id to FooBar instance."""
    def __init__(self, **kwargs):
        self.kwargs = kwargs

    def __call__(self, value, request, *args, **kwargs):
        return FooBar.objects.get(pk=value)

settings.py:

URL_CONVERTERS = {
    'Foo': 'converters.Foo',  # Converts to 'FooBar instance'
}

urls.py:

from django.conf.urls.defaults import patterns
from django_urlconverter import converted_arguments_url

urlpatterns = patterns('views',
    converted_arguments_url(r'^foos/<Foo:foo2>/', 'bar'),
)

views.py:

def bar(request, foo2):
    """View function which gets a converted foo2.
    the foo2 will be a converted parameter, which is the result of Foo converter
    """
    return foo2.title

Contact

If you have questions, bug reports, suggestions, etc. please create an issue on the GitHub project page.

License

This software is licensed under the MIT license

See https://github.com/paylogic/django-urlconverter/blob/master/LICENSE.txt

© 2013 Paylogic International.

django-urlconverter's People

Contributors

bubenkoff avatar youtux avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.