Design tips requested for OOP forum system (using pickle)

Kragen Sitaker kragen at pobox.com
Sat Dec 1 01:36:59 CET 2001


cs1spw at bath.ac.uk (Simon Willison) writes:
> I'm something of a Python newbie but I'm keen to learn so I've decided
> to throw myself in at the deep end.

My suggestion: make sure you get to something executable and usable as
quickly as possible.  The other way lies loss of interest.

> One thing I haven't quite figured out yet is how to relate posts to
> the user object for the user that posted that post.

current_post.user = current_user

> Should I look at
> storing some kind of user ID and then searching through my user
> objects for an object with that ID stored within it every time I
> display a post? That sounds horribly inefficient -

Not if you have a dict of the user objects indexed by user id.  Or you
could just, as above, store a reference to the user object in the post
object.  (This will suck if you don't pickle in a single file.)

> I'm also not entirely sure how to do things like ordering posts witin
> threads by date - should I ensure they are in order within the array
> or sort the objects by their date property (which I assume will
> require me to write my own ordering algorithm, presumably not hard but
> something I've never had to do before).

The easy way would be to keep them in order within the array by
appending them to it when they are posted.

> My final problem (I think) is how to split pickled data up. Should I
> have an OverallForum object which contains ALL the objects (and data)
> within it and pickle/unpickle the whole thing for every page view
> (sounds inefficient) or pickle individual forums in their own files.
> If I store individual forums in their own file how will I maintain
> references to User objects possibly pickled elsewhere?

You might consider 'shelve', which I think solves some of these
problems --- you can mutate a shelved data store without reading and
writing the whole thing.  But I haven't tried it, so I don't really
know.

HTH.




More information about the Python-list mailing list