Skip to main content

An improved URL selector to choose between internal models and external URLs

Project description

django-any-urlfield

https://travis-ci.org/edoburu/django-any-urlfield.svg?branch=master https://img.shields.io/pypi/v/django-any-urlfield.svg https://img.shields.io/pypi/dm/django-any-urlfield.svg https://img.shields.io/badge/wheel-yes-green.svg https://img.shields.io/pypi/l/django-any-urlfield.svg https://img.shields.io/codecov/c/github/edoburu/django-any-urlfield/master.svg

The any_urlfield module provides an improved URL selector that supports both URLs to internal models and external URLs.

This addresses is a common challenge in CMS interfaces; where providing a URLField makes it hard to enter internal URLs, while providing a ModelChoiceField makes it too inflexible. This package provides the both of both worlds.

For more details, see the documentation at Read The Docs.

Screenshot

AnyUrlField, with external URL input.
AnyUrlField, with internal page input.

Installation

First install the module, preferably in a virtual environment. It can be installed from PyPI:

pip install django-any-urlfield

Or the current folder can be installed:

pip install .

Configuration

Add the module to the installed apps:

INSTALLED_APPS += (
    'any_urlfield',
)

Usage

In a Django model, the field can be included:

from django.db import models
from any_urlfield.models import AnyUrlField

class MyModel(models.Model):
    title = models.CharField("Title", max_length=200)
    url = AnyUrlField("URL")

By default, the AnyUrlField only supports linking to external pages. To add support for your own models (e.g. an Article model), include the following code in models.py:

from any_urlfield.models import AnyUrlField
AnyUrlField.register_model(Article)

Now, the AnyUrlField offers users a dropdown field to directly select an article. By default, it uses a django.forms.models.ModelChoiceField field with a django.forms.widgets.Select widget to render the field. This can be customized using the form_field and widget parameters:

from any_urlfield.models import AnyUrlField
from any_urlfield.forms import SimpleRawIdWidget

AnyUrlField.register_model(Article, widget=SimpleRawIdWidget(Article))

Now, the Article model will be displayed as raw input field with a browse button.

Contributing

This module is designed to be generic. In case there is anything you didn’t like about it, or think it’s not flexible enough, please let us know. We’d love to improve it!

If you have any other valuable contribution, suggestion or idea, please let us know as well because we will look into it. Pull requests are welcome too. :-)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-any-urlfield-2.3.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

django_any_urlfield-2.3-py2.py3-none-any.whl (22.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-any-urlfield-2.3.tar.gz.

File metadata

File hashes

Hashes for django-any-urlfield-2.3.tar.gz
Algorithm Hash digest
SHA256 7e361f1def9ae2f9facf213fdcc8c0a921b5503fd5cd2e71b1b80b4957a369df
MD5 34e9d4e6d6f7de5f9c40e8b475959ead
BLAKE2b-256 a015c6c703db34d8e3c11c8265afbca5b77fb2590104381d044a6e74a87a3d04

See more details on using hashes here.

File details

Details for the file django_any_urlfield-2.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_any_urlfield-2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8cce7213a5be8282712f8f0b76779f2fef6cbd62f42277a1140dc49c47905e59
MD5 1aafe22210c46717fc580e6ba6f5952e
BLAKE2b-256 90d367f7daf2d06fd9dad7aec0f530f62ba71c48182ea95d3efb033cf256d90b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page