Template tag to display boolean values?

1,432 views
Skip to first unread message

Derek

unread,
Apr 25, 2010, 10:09:40 AM4/25/10
to django-users
I am looking for a way to display a boolean value, with the "on" / "off" icon that the Django Admin uses in the change list, but within a template view of a single object.  The documentation refers to a "custom tag", but I am not sure if the code or tag is accessible from elsewhere - there is no documentation for any tags to display booleans on the API document page (http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#built-in-tag-reference).  The tag also needs to be able to handle MySQL "booleans" (which are tinyint fields with values of 0 or 1).

Thanks
Derek

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Dmitry Dzhus

unread,
Apr 25, 2010, 12:55:21 PM4/25/10
to django...@googlegroups.com
Derek wrote:
> I am looking for a way to display a boolean value, with the "on" / "off"

http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#yesno
--
Happy Hacking.

http://sphinx.net.ru

derek

unread,
Apr 28, 2010, 4:08:36 AM4/28/10
to Django users
On Apr 25, 6:55 pm, Dmitry Dzhus <d...@sphinx.net.ru> wrote:
> Derek wrote:
> > I am looking for a way to display a boolean value, with the "on" / "off"
>
> http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#yesno
> --
Thanks - but that outputs strings, not URL links to images...

Daniel Roseman

unread,
Apr 28, 2010, 5:12:54 AM4/28/10
to Django users
On Apr 28, 9:08 am, derek <gamesb...@gmail.com> wrote:
> On Apr 25, 6:55 pm, Dmitry Dzhus <d...@sphinx.net.ru> wrote:> Derek wrote:
> > > I am looking for a way to display a boolean value, with the "on" / "off"
>
> >http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#yesno
> > --
>
> Thanks - but that outputs strings, not URL links to images...
>

Except if you define the strings as URL links to images...
--
DR.

derek

unread,
Apr 28, 2010, 5:25:35 AM4/28/10
to Django users
On Apr 28, 11:12 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Apr 28, 9:08 am, derek <gamesb...@gmail.com> wrote:
>
> > On Apr 25, 6:55 pm, Dmitry Dzhus <d...@sphinx.net.ru> wrote:> Derek wrote:
> > > > I am looking for a way to display a boolean value, with the "on" / "off"
>
> > >http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#yesno
> > > --
>
> > Thanks - but that outputs strings, not URL links to images...
>
> Except if you define the strings as URL links to images...
> --

So a '<img src="foo.gif">' string will automatically show as an image
- that's neat!

Daniel Roseman

unread,
Apr 28, 2010, 5:58:59 AM4/28/10
to Django users
On Apr 28, 10:25 am, derek <gamesb...@gmail.com> wrote:
> On Apr 28, 11:12 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
> > On Apr 28, 9:08 am, derek <gamesb...@gmail.com> wrote:
>
> > > On Apr 25, 6:55 pm, Dmitry Dzhus <d...@sphinx.net.ru> wrote:> Derek wrote:
> > > > > I am looking for a way to display a boolean value, with the "on" / "off"
>
> > > >http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#yesno
> > > > --
>
> > > Thanks - but that outputs strings, not URL links to images...
>
> > Except if you define the strings as URL links to images...
> > --
>
> So a  '<img src="foo.gif">' string will automatically show as an image
> - that's neat!

You may need to pass it through the "safe" filter.
--
DR.
Reply all
Reply to author
Forward
0 new messages