Wednesday, May 16, 2012

Re: Is this a bug in the documentation? ModelForm 'fields' attributes throwing error without trailing comma in the Tuple

They put a trailing comma in that example because they're writing a tuple with only one element, and the trailing comma is syntactically required in Python to disambiguate from other types of expression. See:
http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences

"A special problem is the construction of tuples containing 0 or 1 items: the syntax has some extra quirks to accommodate these. Empty tuples are constructed by an empty pair of parentheses; a tuple with one item is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective."

On Wednesday, May 16, 2012 9:22:04 PM UTC-4, Kurtis wrote:
Hey guys,

I've ran into this problem before and it took me a while to figure out the issue. I've ran into it again while just playing around with a small app.

In the ModelForm you can define which fields to use. The documented example is here: https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form

In the 'exclude' attribute, they show the leading comma. In the 'fields' attribute, they don't. I haven't ran their exact example -- but something very similar and I get a weird error, unless I throw in the trailing comma after the final element of the tuple.

I'm just wondering if anyone can verify that this is a bug with the documentation before I start the journey of searching through the existing tickets and filing one if it hasn't been reported.

Thanks!

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate