Yes, that is a better way. but in that way we have to modify the constraints on some tables, adding the "on delete cascade" option.
I found other one (a little more complicated but it should works); it is to use the pg_constraint, pg_class and some other system tables of the pg_catalog to find all the columns of all the tables that has a contype='f' (constraint type is foreign key), using the 'conrelid' and 'confrelid' (http://www.signal42.com/pgsql/catalog-pg-constraint.html) fields to get the rows that i have to delete.
what do you think about it ?