Hi,

I've some rails experience before with several projects and I wonder
how can I accomplish same behavior in django and if it's a good way to
proceed.

When I started using django I create sth like this in my views:

Somemodel.objects.filter(user = request.user)

But I don't like that scheme, I just want to create something similar
to rails like:

"current_user.somemodel.find_by_name('x')"

so that query will automatically know user context.

I noticed that I can extend UserProfile class to sth like this:

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)

    def _get_messages(self):
        from delivery.models import Messages
        return Messages.objects.filter(user=self.user)
    messages = property(_get_messages)
    del _get_messages

and then use request.user.get_profile().messages to fetch messages
that belongs to currently logged user and that works fine, however
that code already calls filter method.
And now what about custom managers, how then can I call them so they
will be aware of current user context ?

Eg. I've a custom manager with method executing custom sql and I want
add support for user context there, how can I do that ?

Is that a good approach or should I done it using another way ?
--~--~---------~--~----~------------~-------~--~----~
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