Skip to content

Instantly share code, notes, and snippets.

@katjakarhu
Created January 9, 2012 10:15
Show Gist options
  • Select an option

  • Save katjakarhu/1582320 to your computer and use it in GitHub Desktop.

Select an option

Save katjakarhu/1582320 to your computer and use it in GitHub Desktop.
Django: render RadioSelect as table
class RadioTableRenderer(RadioSelect.renderer):
def __iter__(self):
choicelist = ""
inputlist = ""
for i, choice in enumerate(self.choices):
id = '%s' % (self.attrs['id'] if 'id' in self.attrs else '')
#label_for = ' for="%s"' % id if id else ''
choicelist = choicelist +"<th>"+choice[1]+"</th>"
inputlist = inputlist + '<td><input type="radio" id="%s" value="%s" name="%s"/></td>\n' % (id, choice[0], self.name)
yield '<table><thead>%s</thead>\n<tr>%s</tr>\n</table>' % (
choicelist, inputlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment