Suppose that you're creating a blog and each blogpost consists of an array of interleaving text fragments and fragments of svg (for instance).
You store each of those fragments in a custom django field (e.g. HTMLField and SVGField).
What's the best way to organize this?
How to maintain the order of fragments? This solution looks ugly:
class Post(models.Model):
title = CharField(1000)
class Fragment(models.Model):
index = IntegerField()
html = HTMLField()
svg = SVGField()
post = ForeignKey(Post)
Fragment.objects.filter(post=current_post).latest('index')to find the largest index. If you want to go from first to last, doFragment.objects.filter(post=current_post).order_by('index'). Just take advantage of ORM operations it's very easy.