[Grok-dev] Re: Remember who added what
faassen at startifact.com
Fri Jun 13 09:33:58 EDT 2008
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.
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.
More information about the Grok-dev