Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let me start with a more simple image list to act as a cleaner example:</p> <pre><code>images = [ (1, u'True', u'file_one.jpg', u'2013'), (2, u'False', u'file_two.jpg', u'2012'), ] </code></pre> <p>You then refine that list of tuples to be choices to use for the form values, essentially the goal is to provide a list of two value tuples to wtforms:</p> <pre><code>[ (1,'file_one.jpg'), (2,'file_two.jpg') ] </code></pre> <p>But you use this list comprehension:</p> <pre><code>rows = [(str(x[0]), x) for x in images] form.images.choices = rows </code></pre> <p>Which will generate:</p> <pre><code>[ (1, (1, u'True', u'file_one.jpg', u'2013')), (2, (2, u'False', u'file_two.jpg', u'2012')) ] </code></pre> <p>Which isn't useful to wtforms, it doesn't know how to handle that tuple within a tuple. So you need to pick the value for the label, or format that data better.</p> <p>So either alter your list comprehension to pick a better description, which will get you to the goal:</p> <pre><code>rows = [(x[0],x[2]) for x in images] </code></pre> <p>Or join all the data together to give a more.. verbose but potentially useful to you description:</p> <pre><code>rows = [(x[0], "\t|".join([str(y) for y in x])) for x in images] </code></pre> <p>Which will result in:</p> <pre><code>[ (1, '1\t|True\t|file_one.jpg\t|2013'), (2, '2\t|False\t|file_two.jpg\t|2012') ] </code></pre> <p>Read up more on <a href="http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehensions</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload