[Grok-dev] Re: Remember who added what

Peter Bengtsson peter at fry-it.com
Fri Jun 13 09:49:47 EDT 2008

2008/6/13 Martijn Faassen <faassen at startifact.com>:
> Peter Bengtsson wrote:
>> I've looked at the wonderful LoginDemo grokapp and it looks like the
>> right thing for me to use.
>> However, how do I "merge" this with my models. I want each object (eg.
>> Comment object) to be "owned" by a user.
>> In Django you do it this way::
>>  from django.contrib.auth.models import User
>> class Comment(models.Model):
>>    user = models.ForeignKey(User, unique=False)
>>    title = models.CharField(max_length=100, db_index=True)
>>    ...
>> What's the Grok way of doing this?
> It depends a bit on what you want to do.
> The simplest thing you could do is to look at request.principal.id (I think
> it was) and simply store that in the comment object. The nice thing about
> Django's use of a relational database is that it's easy to query for all
> comments that a user has. This wouldn't allow you to do so, unless you add a
> catalog index for Comment using grok.Indexes.
And by request.principal.id who do I get the User model object
(...form the PAU presumably)?

> If you're more concerned about security, also use something like
> IPrincipalPermissionMap or IPrincipalRoleMap to assign permissions/roles to
> specific principals. If you want to give objects an 'owner role' you can use
> that.
> Regards,
> Martijn
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev

Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com

More information about the Grok-dev mailing list