Simple and generic application for Django projects to attach and handle links for any object

django apps links generic
pip install django-generic-links==0.4.0


django-generic-links - Attach links to any Django model

The latest version of django-generic-links requires Django >= 1.8. If you want to use it with Dajngo < 1.8 please install a 0.3.x version.


Installing django-generic-links is fairly easy. You can...

(pip install | easy_install) django-generic-links

...or, you can clone the repo and install it the old fashioned way.

git clone git://
cd django-generic-links
sudo python install

then add generic_links to your

        # ...

and then run the migrations!

# python migrate

Using django-generic-links models

Guess you have a music app in your project where you store Artist data. And you would like to store and display links for each artist, say his facebook page, his profile, his youtube artist page and the like:

>>> from generic_links.models import GenericLink
>>> from music.models import Artist
>>> lou_reed = Artist.objects.get(pk=1)
>>> lou_reed
<Artist: Lou Reed>

>>> link1 = GenericLink()
>>> link1.title = "Wikipedia Page"
>>> link1.url = ""
>>> link1.is_external = True
>>> link1.content_object = lour_reed

>>> link2 = GenericLink()
>>> link2.title = "Youtube artist page"
>>> link2.url = ""
>>> link2.is_external = True
>>> link2.content_object = lour_reed

>>> from generic_links.utils import get_links_for
>>> qs = get_links_for(lou_reed, is_external=True)

Generic Links admin

Since a GenericLink instnace will be associated to another object you usally wish to show an inline model admin form in that model form.

# this is your app's
from django.contrib import admin

from generic_links.admin import GenericLinkStackedInline

from my_app.models import MyModel

class MyModelAdmin(admin.ModelAdmin):
    # ...
    inlines = [GenericLinkStackedInline]
    # ..., MyModelAdmin)

Using django-generic-links templatetags

Now guess you have an artist page. You're passing artist object using template context and you want to get all the links for it:

{% load generic_links_tags %}

<h1>{{ }}</h1>
<p>{{ artist.description }}</p>

<h2>Links for {{ }}</h2>
{% get_links_for artist as artist_links %}
{% for link in artist_links %}
    <li><a href="{{ link.url }}" title="{{ link.title }}">{{ link.title }}</a></li>
{% endfor %}

Questions, Comments, etc?

You may use Github comments to comment this code or the project issues to open issues if you find a bug or a missing feature you'd like to have.

You can also follow me on Twitter - @matagus.

Want to help?

If you'd like to help, write example code, contribute patches, document things on the wiki your help is always appreciated! Just fork the project, clone your repo, commit, push and send me a pull request


django-generic-links is released under an BSD License - see the LICENSE file for more information.

Bitdeli Badge