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.

For more configuration options of the register_model() function, see the documentation of the AnyUrlField class.