Sorry if I'm getting a little far out here.

I have two models, a parent and a child with a FK relationship (See
the code below for example) and I have a method in each called
is_owner.  For the child it checks to see if a user passed is the
objects owner OR if that user passes the parents is_owner method.

I use this in a decorator that I use in views to give permission for
updating or deleting based on checking permissions OR if they pass the
objects is_owner check.

My problem is with new child objects.  How would I check for new child
objects if the parent is an owner so they can get the proper Form to
create it?



class Project(models.Model):
    owner = models.ForeignKey(User)

    def is_owner(self, user):
        if user == self.owner:
            return True
        return False


class Release(models.Model):
    project_fk = models.ForeignKey(Project)
    owner = models.ForeignKey(User)

    def is_owner(self, user):
        if user == self.owner:
            return True
        if self.project_fk.is_owner(user):
            return True
        return False
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to