Przemyslaw Wroblewski wrote:
> 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')"

You want this:

     request.user.somemodel_set.filter(name='x')

This will work as soon as you have a foreign key to User in SomeModel.

If you don't like automatically named attribute "somemodel_set" you can 
set this name on a foreign key relation:

     class SomeModel(models.Model):
         user = models.ForeignKey(User, related_name='somemodels')

and then use:

     request.user.somemodels.filter(name='x')

--~--~---------~--~----~------------~-------~--~----~
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