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
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. :-)
Release files for django-any-urlfield 2.7.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-any-urlfield-2.7.post1.tar.gz | 28.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_any_urlfield-2.7.post1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:61.5 kB
Release files / django-any-urlfield-2.7.post1.tar.gz
| Download URL | django-any-urlfield-2.7.post1.tar.gz |
|---|---|
| Size | 28.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd2fec1811dbc07713d413d071653d13dddd6df711d54ca06fa361569a02afc2
|
|
BLAKE2b-256 checksum How to use checksums |
9869f01ba2def607bfe96bd121343df120641afce3dc9b8f533e317f0c14864d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.1
|
Release files / django_any_urlfield-2.7.post1-py3-none-any.whl
| Download URL | django_any_urlfield-2.7.post1-py3-none-any.whl |
|---|---|
| Size | 32.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
360d31917e81ff0c4cf2a976435968c8e8ccd560feef18983ee3fd453df3f3dd
|
|
BLAKE2b-256 checksum How to use checksums |
f9c0fb20c17fba3444b98f42680d8f65f9436f45f9060aedad38367dedf413b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.1
|