Skip to main content

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

Project description

https://img.shields.io/travis/edoburu/django-any-urlfield/master.svg?branch=master https://img.shields.io/pypi/v/django-any-urlfield.svg https://img.shields.io/pypi/l/django-any-urlfield.svg https://img.shields.io/codecov/c/github/edoburu/django-any-urlfield/master.svg

django-any-urlfield

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:

pip install django-any-urlfield

Add the module to the installed apps:

INSTALLED_APPS += (
    'any_urlfield',
)

Usage

Add the field to a Django model:

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.

Register any model that the AnyUrlField should support linking to:

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

Now, the AnyUrlField offers users a dropdown field to directly select an article.

The default field is a django.forms.models.ModelChoiceField field with a django.forms.widgets.Select widget. 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))

That will display the Article model 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. :-)

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.6.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

django_any_urlfield-2.6-py2.py3-none-any.whl (29.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django-any-urlfield-2.6.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/38.5.2 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.1

File hashes

Hashes for django-any-urlfield-2.6.tar.gz
Algorithm Hash digest
SHA256 93aa7d04887a4aaefb41d8850515b6b4bd1d4577854ab0f811aea806dabc51e3
MD5 189bf58a12b943ce5a5cfa034de8bde4
BLAKE2b-256 a74703435056c35a5e7ab83fbca6d33c898091e427570fedb883d1a81e1619c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_any_urlfield-2.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/38.5.2 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.1

File hashes

Hashes for django_any_urlfield-2.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 42ce4950aad986e597441ed8c12bee53685be73fe2ed246aa0c8b1644f44a1e6
MD5 e59ae56199fcefadc3131430b5a04941
BLAKE2b-256 0ef2b1f1ebf37d19eac615c157ff9c1fc134ff5d7fe470415376acf65cac1dcc

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