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

django-generic-links: attach and handle links to any django model


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 syncronize your database!

# python syncdb

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)

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.