Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Larry Horseplay
Oct 24, 2002

I've been trying to figure this out for a little bit, and I think I'm confused.

I'm trying to build a survey form. You know, the kind where it asks you questions and you fill in a circle for "Strongly Agree", "Agree," "Disagree", etc.

My model has each of those in an int field with a choices enum.

Now, the thing works fine. About an hour of coding, most of that typing all the questions into the verbose names, and it's done.

However, the widgets look like crap. The standard RadioSelect outputs as lists. No problem, right? I just wrote a custom renderer.

code:

class AgreeRadioRenderer(forms.widgets.RadioFieldRenderer):

    def render(self):
        return mark_safe(u'<tr>%s</tr>' % u'\n'.join([u'<td>%s</td>' % w for w in self]))

However, I can't get the text outside of each input tag to not render. So, each radio button has its choice next to it. "Strongly Agree," etc. I just want a radio button, no labels, no anything. How do I do this?

edit: I just blanked the strings in the enum structure. I don't know if this is the "right" way to do this, but it works.

Larry Horseplay fucked around with this message at 22:44 on May 7, 2008

Adbot
ADBOT LOVES YOU

Larry Horseplay
Oct 24, 2002

Yep, that's exactly how it looks. And it works!

I think it's a testament to how good Django is that whenever I have to do anything somewhat "manually" I wonder if I'm doing it right.

Larry Horseplay
Oct 24, 2002

Strangely enough, I happen to work for a non-profit where accessibility is an issue.

Eventually I'll have to create a subclass and render it myself, I guess. But for now I'll get the thing working.

I'm using the reportlab python package to make PDFs right now as part of the package, actually. It's pretty cool :)

Larry Horseplay
Oct 24, 2002

Anyone have any Django-based calendaring code they wouldn't mind sharing? It seems like a common use, but I don't see much sample code via Google.

(If no one's got any, though, I'll post what I have once I finish it up.)

Larry Horseplay
Oct 24, 2002

Wulfeh posted:

http://www.djangosnippets.org/tags/calendar/

There a couple there, and if those aren't exactly what your looking for, I am sure they would be good references

One of those is exactly what I needed. It even works with the models I've already created! I totally forgot about djangosnippets, too (doh!) Thanks!

Larry Horseplay
Oct 24, 2002

I'm writing a survey application. For items that have multiple checkbox entries (i.e. pick as many choices as you want), I was thinking of using a CommaSeparatedIntegerField in my model, and a MultipleChoiceCheckbox in the form. Is the the "right" way to do this?

Adbot
ADBOT LOVES YOU

Larry Horseplay
Oct 24, 2002

bitprophet posted:

Guess it depends on what exactly you need to do with those values on the query side of things, but it could be an OK choice, nothing obviously wrong with it that I can see.


Also, hooray! the book is officially out. Got my hard copies last night. Here's a crappy iPhone photo:


Congrats!

Most likely I'll just be exporting stuff to XLS sheets for people in my organization to play with for now, so I don't think the comma separated integers will be an issue. Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply