Let me start out by saying this feels a little over engineered but I
wanted to see what people thought anyways.

I would like to create a list similar to a Facebook wall. You can post
stuff and attach content to the post. In the past I have create a
table with properties for all content formats and only set the one I
was interested in. Thats bad cause you have all these empty fields for
no reason. I have also just created foreign key to a separate content
model (one for each format). That means you have to joins all the
time. Since at the end of the day all of these formats are stored as
strings, I can just use ONE content field. However I lose all the nice
Image and File handling stuff Django gives you. So what if there was a
ModelField that could change itself at runtime. Would I be better of
doing this feature in a non-relational database and handling all the
file upload stuff myself?

All content will be represented in the database as a VARCHAR. I'll add
some pseudo code that might explain it better than i can.

choices = (
    (0, 'note'),
    (1, 'link'),
    (2, 'image'),
)

formats = (
    (0, models.CharField, {'max_length': 200}),
    (1, models.UrlField,),
    (2, models.ImageField, {'upload_to': 'uploads'),
)

class Item(models.Model):
    title = models.CharField(max_length=200)
    format = models.IntegerField(choices=choices, default=0)
    content = MultiFormatField(formats=formats, format_field='format')
# changes based on instance.format

Thanks for taking the time to read this over.

- Sean

--

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


Reply via email to