Hi all. I'm pretty new to django, but I'm catching on slowly but
surely. So please bear with me :)

For one site I'm working/learning on, I'm trying to build in "Pods" of
static content that can be added as necessary to any page (or later,
series of pages). The individual pods can be moved into different
content areas of the page, depending on the content manager's wishes.
Here's a simplified sample of the models:

class Page(models.Model): # mostly borrowed from flatpages
    title = models.CharField(_('title'), max_length=200)
    content = models.TextField(_('content'))
    pods = models.ManyToManyField('pod', blank=True)
    ...

class Pod(models.Model):
    name = models.CharField(max_length=100)
    content = models.TextField(blank=False)
    order = models.SmallIntegerField(choices=POD_ORDER_CHOICES)
    style = models.CharField(max_length=20,choices=POD_STYLE_CHOICES)
    placement =
models.CharField(max_length=20,choices=POD_PLACEMENT_CHOICES)
    ...

Pages are called using select_related(), which retrieves the
associated Pods. So in the template, I have several areas like this:

{% block leftcolumn %}
    <div id="left_column">
    {% for pod in page.pods.all %}
        {% ifequal pod.placement "left" %}
        <div class="pod">
        <h2>{{ pod.Title }}</h2>
        {{ pod.Content|escape|linebreaks }}
        </div>
        {% else %}
        {% endifequal %}
    {% endfor %}
    </div>
{% endblock %}

It works, but I definitely know it's not the best way to do it. I have
two primary problems with it.

First, if there are no items in that block, then I don't want to show
that <div id="left_column"> on the page at all. How can I choose to
display the contents of a block depending on if a pod exists that
meets the select criteria? I know I'm missing something simple, but I
can't put my finger on it.

Second, it is obviously and woefully inefficient to do this for
several blocks on the page. I may have 5 or more, and I may want to
add some in the future. Is this the place for a custom templatetag?
Has someone already put something like this together?

If I'm completely off-base and thinking about this wrong, let me know.
I'm still learning!
--~--~---------~--~----~------------~-------~--~----~
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