Monday, July 26, 2010

Inline formset when pk doesn't exist

I have 2 models

class Item(models.Model):
fields here

class ItemImage(models.Model):
item = models.ForeignKey('Item', null=True, blank=True,
related_name='images')

I want a single 'form' where a user can add an Item and an ItemImage
(actually many images but that's irrelevant at this stage). I want to
use an inline formset but the Item instance doesn't exist so there's
no primary key, I have tried but get an error relating the the lack of
primary key (...django/forms/models.py in _get_foreign_key, line 796).

I'm pretty sure this can't be done with inline formsets so I figure
that I should add an ItemImage formset to the Item form somehow, I
just don't know how (and it doesn't seem to be covered in the docs).

I'd appreciate any help I can get as I've hit a brick wall.

Many thanks


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment