- If you want retrieve all Person objects that can be viewed by a
user, this is possible with this query:

persons = Person.objects.filter( Q(owner=my_user) | Q(public=True) )

my_user is the current logged user, so this query, in designed to be
executed in a view function.

- If you want to retrieve the current logged user at model level, this
is a little more complicated, because models are note designed to see
what happen at process level, but it still possible, look at this:
http://lukeplant.me.uk/blog.php?id=1107301634


So you can finally write a custom manager in which you will have
something like this:

my_user = get_current_user()
Person.objects.filter( Q(owner= my_user ) | Q(public=True) )


On 17 jan, 03:18, John M <[EMAIL PROTECTED]> wrote:
> I want to create a model system where a user can own a record (i.e.
> foreign key to users table) and those records are only seen by that
> user OR the user can choose to make the record public (boolean field
> in model) that allows others to view-only the record.
>
> I was trying to come up with some simple model managers to do this,
> but wanted to get some input first.
>
> a Model something like:
>
> class Person(models.Model):
>     first_name = models.CharField(max_length=30)
>     last_name = models.CharField(max_length=30)
>     owner = models.ForeignKey(user)
>     public = models.booleanfield()
>
> Basically, this will be a site where users can keep track of their
> stuff, but allow others to view what they have too (the person model
> isn't what I'm going to use, just an example).
>
> Any thoughts?
>
> Thanks
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to