I'm working on a way to allow our content creators to put certain form
elements on pages based on question types (open text, radio, checkbox,
likert scale, etc).  I can see 2 ways of accomplishing what I'm trying
to do.

As pretext, I have 2 models: Question and Option.  Option has a
ForeignKey relationship to Question.

My goal is to specify the HTML for each question type once and not in
various templates.

1) Use inclusion tags.

So I'd create a method that takes a context which contains my question
object and also pass in a question id.  The method would return a data
structure with the question values and option values like this:

    return {
        'qtitle': question.title,
        'options': question.option_set.all().order_by('sequence')
    }

I'm pretty sure I can iterate over the internal options list just fine
in the template context.  The inclusion tag would render the HTML which
would be included in the main template.

2) Simply use template.render(context) and build the same context as
above.  I'd be adding the raw HTML to the main template context to
output rather than calling an inclusion tag to return the HTML.  This
would probably work just fine as well.

Is one more efficient?  Is one more preferred?  I'm leaning towards #1
since it seems like its purpose.  In some ways #2 seems like less code
and keeps more in the views.py file rather than #1 requiring
templatetags.

Thoughts?

Thanks,
Rob


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to