views:

132

answers:

1

Django 1.1

models.py:

class Property(models.Model):
    name = models.CharField()
    addr = models.CharField()
    phone = models.CharField()
    etc....

class PropertyComment(models.Model):
    user = models.ForeignKey(User)
    prop = models.ForeignKey(Property)
    text = models.TextField()
    etc...

I have a form which needs to display several entries from my Property model each with a corresponding PropertyComment form to collect a user's comments on that property. In other words, allowing a User to comment on multiple Property instances on the same page.

This seems outside the intended usage of an Inline formset since it is multi-model to multi-model vs. single-model to multi-model. It seems like trying to iterate through the Property instances and create an inline formset for each is not only clunky, but I'm not even sure it could work.

Any ideas on where to start on this?

A: 

Have you thought about using the comment framework:

http://docs.djangoproject.com/en/dev/ref/contrib/comments/

If that doesnt work for you then maybe look into inlineformset_factory:

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

from django.forms.models import inlineformset_factory 
PropertyCommentFormSet = inlineformset_factory(Property, PropertyComment)
property= Property.objects.get(name=u'some property name')
formset = PropertyCommentFormSet(instance=property)
etc...
Dave