How to approach generating generic related links (e.g. Comments / Tags) in Django

Since I didn't find a linked links app that works with Django 1.0 / trunk, I was looking for my own.

I would like to add "Related Links" to the models in the same general way as the comment environment or tags.

I've looked at the Content Type Documentation , but can't wrap myself around (and don't find much documentation) how to use Common Inline Forms - which is what I'm sure I should be using, but correct me if I'm wrong.

My particular requirement is to be able to associate these "linked links" with just about any model, and have a form that is accessible outside of the Admin - I will register members of a specific role adding these links in my particular case.

I thought about digging into the source of the Comments app, but I know it uses special template tags, etc., and I'm just not sure if that would be overkill for this task.

Look for links, additional documentation, and maybe even examples of using generic inline forms (in Generic Views) or solving the problem differently if I'm not mistaken.

EDIT: I used James Bennett's example from Generic Inlines to create and successfully use linked links in Admin. So the real question is: How do I use James's linked links outside of admin?

+2


source to share


1 answer


You can use django.contrib.contenttypes.generic.generic_inlineformset_factory

for this. It has the same interface as inlineformset_factory

(with two additional parameters: ct_field

and fk_field

, these can be used to specify field names associated with your content type instead of inlineformset_factory

fk_name

).

The documentation for inlineformset_factory

can be found here:



http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets

The documentation for the formsets is helpful too.

+3


source







All Articles