On Tue, Apr 15, 2008 at 9:02 AM, per9000 <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I have added a * to required fields. (Some of my forms do not have any
> required fields.) I want to do this:
>
> <html>
>  {% if form|has_req_field %}
>      * = Required Field
>  {% endif %}
>
>  {# put form here #}
>
> </html>
>
> And my filter looks like this:
>
> def has_req_field(value, arg=None):
>
>    for field in value.fields:
>        if field.field.required:
>            return True
>
>    return False
>
> I get the impression that my template truns the form into a string and
> then passes the string into my filter function ('str' object has no
> attribute 'field').
>
> Is there any way to get the form intact out of the template and into
> python?
>
> Or is there a better way to find out if there is at least one required
> field of my form.
>
> Thanks!
>

I don't know that filters are intended to be used in if blocks like that.
It would seem more natural to have a has_req_field method in your form and
write:

{% if form.has_req_field %}

(Yes, then each form you want to do this with has to have this method, but
there are Python ways to enable that without actually having to duplicate
the code in each form.)

Karen

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