I have a Resource, which can either be an image, a link or a
document.  What is the cleanest way to handle this?

My thoughts are either, have them be attributes on the Resource
object:

    class Resource(models.Model):
        name = models.CharField(...)

        # One of these
        image = models.ImageField(...)
        link = models.UrlField(...)
        doc = models.FileField(...)


Or, OneToOne with choices:

    class Resource(models.Model):
        name = models.CharField(...)

    class ImageAttachment(models.Model):
        image = ...
        resource = models.OneToOneField(Resource)

    class LinkAttachment(models.Model):
        url = ...
        resource = models.OneToOneField(Resource)

    class DocumentAttachment(models.Model):
        file = ...
        resource = models.OneToOneField(Resource)

Neither seems especially clean, I feel like I'm missing something
idiomatic here...

Having the attachments as fields seems not-so-clean, but for vague
reasons.

The OneToOne kind of stinks because if I'm listing resources, it seems
I have to have a bunch of try:except: blocks to figure out which
resource exists.

Thoughts/suggestions?

Regards,
Tom

-- 
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=en.

Reply via email to