views:

148

answers:

2

According to the documentation, a class can have the meta option permissions, described as such:

Options.permissions

Extra permissions to enter into the permissions table when creating this object. Add, delete and change permissions are automatically created for each object that has admin set. This example specifies an extra permission, can_deliver_pizzas:

permissions = (("can_deliver_pizzas", "Can deliver pizzas"),)

This is a list or tuple of 2-tuples in the format (permission_code, human_readable_permission_name).

Would it be possible to define permissions at run time by:

permissions = (("can_access_%s" % self.pk, /
                "Has access to object %s of type %s" % (self.pk,self.__name__)),)

?

A: 

I think in the context of the Meta class, you don't have access to self.
If you look for a solution for the admin application, read this about row level permissions.

There is also says:

For public-facing (i.e., non-admin) views, you are of course free to implement whatever form of permission-checking logic your application requires.

Felix Kling
A: 

No, this wouldn't work, for a number of reasons. Firstly, as Felix points out, you have no access to self at that point. Secondly, as the documentation you quoted states, this is a list of items to enter into the permissions table - in other words these are actual database rows, which are created by manage.py syncdb.

Daniel Roseman