Designing an Application

Jeff Mitchell jeffm at centurionsw.com
Tue Jun 20 10:20:20 EDT 2000


Disclaimer: I've not done this in python and I don't known anything
about Gadfly.

Most databases can be queried for metadata about a table (column names
and types) and a data structure can be built from that on the fly. The
database won't (at least in my experience) know enough to for you to
determine if the data is a reference to another object, so you'll have
to create a naming convention for columns that supply that, for example:

	create table students (
		student_id	integer,	## a field in the student object
		ref_animal	integer,	## reference to the animal table
		);

So, in this senario any field name that begins with 'ref_' is a
reference to data stored in table named after the underscore.

I've done this (in C, no less) and it works well. The biggest problem is
constructing the user interface on the fly , which is not terribly
difficult, unless you want it to look good ;-)

Hope this helps -- Jeff

lexberezhny wrote:
> 
> Hi,
>   I am not sure if this is appropriate to this list but I though I would try
> anyway. I am writing a Grade book program using a gadfly database, and a
> PyGTK front end. I split everything up into a database library (all the SQL
> stuff, and database initialization), grade book library (class definitions
> for a student, assignment, etc), and an interface.py GTK file. Here is an
> stripped down student class:
> 
> class Student:
>     def __init__(self, studentID):
>         student = database.getStudent(studentID) # runs the SQL query and
> returns a student list
>         self.Name = student[0]
>         self.Grade = student[1]
>         etc...
> 
> My future goal would be to allow the teacher to add his or her own
> properties to a student, and maybe even add independent object (ie a teacher
> wants to keep track of the favorite animals of each student, so there would
> be an object for an animal maybe, and a property in the student table to
> relate to the animal table, something to that effect, etc..) Well I can not
> think of a good way to implement this without putting a few hacks together.
> I guess what I'm trying to do is create dynamic classes? Or is there some
> other way to do this? Any suggestions or experience tips would be greatly
> appreciated. On a side note I am doing this for a school project, so I'm
> learning as I'm going along and willing to read any documentation, etc.
> 
>  - Lex Berezhny



More information about the Python-list mailing list