Friday, January 23, 2009

Adding custom attributes to django modelform fields

(permalink)
Finding an elegant way to solve a particular problem that's been stumping you for a while is always a nice feeling.

Savraj and I were talking about django's modelforms today. My modelform conversations always seem to gravitate toward lamenting about how it is hard to customize them. That's been a problem that's bothered both of us in the past. My solution was to customize the CSS of the form. This worked for some elements (such as the form's length), but not others. Another solution is to explicitly declare each field with the customized attribute, but this seams to defeat the whole purpose of modelforms.

I just figured out a more flexible solution that I'll share here. It allows me to modify the attributes of a django widget without explicitly declaring the field (which is great). In the example I modify the onclick attribute. You can use it to modify any attribute you want (eg. size, max_length, value, etc).


class PhotoForm(forms.ModelForm):
    class Meta:
        model = Photo
    def __init__(self, *args, **kwargs):
        super(PhotoForm, self).__init__(*args, **kwargs)
        self.fields['name'].widget.attrs['onClick'] = "this.value =;"


Thursday, January 08, 2009

The coolest thing you'll see at CES all day

(permalink)


Anybots just announced QA, a new tele-operated robot. I've been fortunate enough to have spent some time with it and it's pretty impressive. If you're going to CES, it's worth checking out in person. They're in the Robotics tech zone at the Sands Expo center (Booth #72239, Exhibit hall C).

The form factor is similar to Monty except much simpler. This means the cost will be in the thousands, not the hundreds of thousands. Unlike monty, QA is 100% battery powered, and gets 4-6 hours of runtime on every charge. Monty's pneumatics required it to be tethered at all times. Also, its much lighter at around 35lbs. Monty is too heavy to pick up.

The obvious disadvantage is that QA doesn't have arms and therefore no real way to manipulate its environment. While I'm sure that it was a hard decision to move forward without arms, it was probably smart. Arms are hard to get working reliably and require a custom user interface. QA can can be controlled by any laptop that's connected to the internet.

I can imagine a number of applications where a mobile telepresence robot is still valuable - even without arms. However it will take people more creative than me to think of all the ways QA could be used. We might see these robots patrolling dangerous neighborhoods in a few years, calling in the cops when any suspicious activity is observed. Who knows.

Edit, 10:09AM Anybots has updated their website with more details. Head over to their about the robots page.




Labels: