I’ve had django-flag https://github.com/pinax/django-flag on my todo-list , finally got around to it and found that there was no documentation written for it.  Well no worries a quick browse through all the code in the package made it easy to figure out the workings.  Anyhow here’s how you use it !

1. Install via pip

pip install django-flag

2. Edit settings.php and add the following to your INSTALLED_APPS


3.  Modify urls.py and add the following:

(r’^flag/’, include(‘flag.urls’)),

4. Finally use it in a template:

{% load flagtags  %}
{% flag object attribute %}

Let me explain the object attribute part, in order to flag any content for a model , that model needs to have a fk attribute to the User model.   So the first argument is the object you would like the flagging to be done on and the second argument is the attribute, which can be whatever you named the fk pointing to the User model.


Additional info:

There is a weird / useless check  in the view which checks if the creator of the object exists, if not assign None, well this fails because the fk doesnt except None.  Anyhow
I removed it since that case will never happen in my view and is not needed.  Also there is no unique check , currently the same user can flag the content more then once.  I plan to fix that as well and I am going ajaxify this whole workflow so it’s a little cleaner than its present state.  If you would like the cleaned up view, unique check and ajax code let me know and I can put that up as well.  As always opinions, complains, comments are welcome.


Update 2-20-2012

Here is the updated view & model:

model views