Hi list!
In the last past hours I've been thinking about how
to include images into my django blog application.
At first, I added a new field to my "Entry" django
model and named it "image". This worked but I decided that
(maybe) I want to include more than one image in a blog
entry. So I created an "Image" model and created
a relation between the "Entry" via the ManyToManyField.
Now I'm thinking about how I could include the images
into the 'Entry' without typing in the whole url on my one.
So I came up with this piece of code:
class Entry(models.Model):
images = models.ManyToManyField(Image)
....
def save(self):
"""Replace $imageX with the image url before saving."""
image_list = self.images.all()
for i in xrange(0, len(image_list)):
self.intro = self.intro.replace("$image%i" % i,
image_list[i].get_image_url())
self.body = self.body.replace("$image%i" % i,
image_list[i].get_image_url())
Now I can insert "$image0" to include the first image, "$image1"
for the second.. (or when using markdown, what I do: ]).
It works more or less but this is very ugly in my opion.
So has anybody of you came up with a better solution
to this problem?
Thanks!
Kai
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---