Facing new challenges everyday

Changing field widget attributes from view code

February 3rd, 2009

Yesterday I finally wrote my first Django application, this application is a basic crud that contains two pages, one to list costumers and another to change costumer data.

My biggest challenge was related with some form features, with Django forms you can programatically create a view form that contains several fields with its constraints and optionally associate a Django widget with this field. Django forms also have a very powerful validation engine and some form field constraints must be defined for this purpose.

This application uses the same page for two purposes, to add new data or edit data, in this scenario I must use a hidden field to be used as flag indicating in which mode the page is, adding or editing data, I must also change the readonly attribute of input widget used by costumer id form field since the user can’t change costumer id.
(more…)

Post to Twitter

When convention over configuration sucks

February 2nd, 2009

Last saturday I wrote a small application using rails 2.2.2, rails is pretty handy in many ways, when writing models, controllers and views, I could get this application working almost like its jsf version, except for one thing, convention on primary keys.

Rails has a convention on primary keys, if you are using sqlite as database you are limited to use an auto-increment column as primary key, no user provided id is allowed. You can customize the column name of primary key, but nothing more.

To change the column name of your primary key you must call set_primary_key method on your model class, like below:

1
2
3
4
class Supplier < ActiveRecord::Base
   set_table_name "supplier"
   set_primary_key "fid"
end

Post to Twitter

« Previous Page

Visitors Around the World

Polls

How Is My Site?

View Results

Loading ... Loading ...

Categories

Meta

Links

hosted by easy2use.net