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. 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
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.
Source Distribution
Built Distribution
File details
Details for the file django-any-urlfield-2.0.1.tar.gz
.
File metadata
- Download URL: django-any-urlfield-2.0.1.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b9d85566e9f921878469aa254e00eb7aef4219e67c3b682313cfb64160b5752 |
|
MD5 | fe40c7f301e3a057d721323e0b09a470 |
|
BLAKE2b-256 | dfc875bd02f3ab196e2f0606776fde8b554d4f52a9b09a2f1b3af947f145fb50 |
File details
Details for the file django_any_urlfield-2.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: django_any_urlfield-2.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fe057c98f88aad51538fc398e9c6d870158dca6d4ca163a5c66765f18f90bf4 |
|
MD5 | 53af6ccca85599c2f629a4e7a534a164 |
|
BLAKE2b-256 | 1bca71b10b658923454208a9343cbb2c2ff4f7acc1b03e727a5f6889c5c4fbf7 |