On 8/3/06, OriginalBrownster <[EMAIL PROTECTED]> wrote:
>
>
> However what I want to do is display only the files that the user has
> uploaded (from the turbogears identity)
>
> Thus i want to search the databse for the upload_user col and search
> for the current user, and then display thier files.
>
>
> class UploadedFile(SQLObject):
>         filename = StringCol(alternateID=True)
>         abspath = StringCol()
>         uniqueid = IntCol()
>                 upload_user=StringCol()
>

Firstly, your UploadedFile class is a little out of sorts.  If
uniqueid is supposed to be similar to an auto-incremented numeric ID
for each record then it is not needed.  SQLObject automatically takes
care of giving each object it creates an ID.  Just try getting an
instance of UploadedFile, e.g. file = UploadedFile.get(1) and then
calling file.id.  It should give you the auto generated ID and it's
much better to rely on SQLObject to automatically assign this for you.

Second, your upload_user column should be a ForeignKey to link the
User class.  I would rewrite your class as follows:

[code]

class UploadedFile(SQLObject):
    # No alternateID.  Filenames shouldn't *have* to be unique.
    filename = StringCol(length=255)
    abspath = StringCol(length=255)
    upload_user = ForeignKey("User")

[/code]

Then you need to add the following line to your User class:

[code]

class User(SQLObject):
    ...
    files = MultipleJoin("UploadedFile", joinColumn="upload_user")
    ...

[/code]

I've specified the joinColumn above because you've named your field
"upload_user" and not just "user".  If you change that column's name
you can remove the joinColumn parameter as SQLObject will
automagically find the right column to reference as the foreign key.

Then, for any given user you can get all the files they've created.
Try the following in tg-admin shell.  I'm assuming that you have a
user with an ID of 1 and that user has files uploaded.

>>> user = User.get(1)
>>> userfiles = user.files

It's as simple as that.  userfiles should now be a list of all the
FileUpload instances that user 1 has created.

Hope this helps,

Lee


-- 
Lee McFadden

blog: http://www.splee.co.uk
work: http://fireflisystems.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to