I hope I can explain this well, because I've been wracking my poor
little brain trying to figure out how to do this :)

I'm trying to create a flexible CMS.  I want it to be easy for users
to create a Page, and attach all kinds of content ("components") to
that page.  These components would all be Model classes.  Here are two
simple examples of the components I had in mind:

class TextSnippet(models.Model):
    body = models.TextField()

class Photo(models.Model):
    image = models.ImageField(upload_to="photos")

The idea is that a user add an arbitrary number of these components to
a Page model.  A Page model is nothing more than a container to hold
components, and a URL associated with the Page, something like:

class Page(models.Model):
        url = models.CharField( maxlength=100, unique=True,
validator_list=[validators.isAlphaNumericURL])

The problem is that I can't figure out a good way to associate
instances of TextSnippet and Photo with a page.  It's obviously a many-
to-many between the components and pages (a component like a photo can
be on many pages, and a page can have many components), but I also
need to store more information about that particular page-component
relationship, for example a IntegerField that specifies the
component's position on that page.  Here's what I've come up with so
far:

class PageComponent(models.Model):
        page = models.ForeignKey(Page, related_name="components",
edit_inline=models.TABULAR)
        content_type = models.ForeignKey(ContentType)
        object_id = models.IntegerField(core=True)
        position = models.IntegerField(default=0, blank=True)


It "works" not too bad.  Conceptually (from the shell), I think it
does what I want.  However, I'm having a HECK of a time getting the
Page form in the admin to work in an intuitive way.  When adding
components to a page, the user sees a drop-down list of content_types,
and has to enter an object_id.  It works for me because I know what to
put for the object_id, but a regular user wouldn't....

I think this would require me to write a custom form class for adding
and editing a page, but with these relationships I really don't even
know where to begin :S

If anyone can provide advice (or just flat out tell me if I'm thinking
about this wrong), it would be much appreciated!

Thanks,
Kyle


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to