An improved URL selector to choose between internal models and external URLs
Project description
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. :-)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size django_any_urlfield-2.5-py2.py3-none-any.whl (28.2 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes View |
Filename, size django-any-urlfield-2.5.tar.gz (26.6 kB) | File type Source | Python version None | Upload date | Hashes View |
Hashes for django_any_urlfield-2.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35bf066acfad9b822060e0d8a549c1fc1ebfa7979f73c941325f1f750f3b258d |
|
MD5 | 404d9d85f9908da603867e987a4cb022 |
|
BLAKE2-256 | 376fced7ace9fd13b60a246f017107931e69406e9d767fc33ee4205a7836ff8c |