This may have been asked and answered before, but it's hard to figure
out what terminology I should be using.
Say I have a couple (or more of models) that are related using foreign
keys, like so:
class Publication(models.Model):
title = models.CharField(max_length=250)
isbn13 = models.CharField(max_length=13, primary_key=True)
class PublicationImage(models.Model):
image = models.ImageField(upload_to='publications')
position = models.IntegerField(max_length=2)
publication = models.ForeignKey(Publication,related_name='images')
Is it possible to take a literal form of a publication and easily
convert it into a model instance and insert or update as required. ie
something like:
record = {
'title': 'Book Title',
'isbn13': '123456789012A',
'images': (
{
'image': '/path/to/image1.jpg',
'position': 0,
},
{
'image': '/path/to/image2.jpg',
'position': 1,
},
),
}
Publication(record).save()
This approach seems to work if it's a flat model (ie no foreignkeys), so
far my attempts to do this neatly have failed. I've got code where if
the publication already exists I delete all the existing images and add
them again. I realise this is quite similar to JSON serialization but
the literal is already python rather than a javascript string and I want
to define the foreign key models inline rather than referencing the
primary key.
Any insight would be greatly appreciated.
Regards,
Andrew Ingram
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---