List Info

Thread: limit_choices_to




limit_choices_to
user name
2006-03-26 19:38:37
Hello,

Is there someone kind enought to provide me some guidance on
the usage
of "limit_choices_to" in a foreign key?

my model look like this:

class Profile(meta.Model):
    user =meta.ForeignKey(User)
    pseudo = meta.CharField(maxlength=30,core=True)
    [...]
    def __repr__(self):
        return self.pseudo
    class META:
        admin = meta.Admin()
class Announce(meta.Model):
    titre = meta.CharField(maxlength=30)
    [...]
    profile =meta.ForeignKey(Profile,
limit_choices_to={'user__exact' :
meta.LazyDate()})
    def __repr__(self):
        return self.titre
    class META:
        admin = meta.Admin( )

The User is the regular django.models.auth class. I would
like to
filter the Profiles on the attribute user. the objective it
display
only the profiles of the logged in user.

I found that it should look like somelike this:

profile =meta.ForeignKey(Profile,
limit_choices_to={'user__exact'=##?the curentuser?## :
meta.LazyDate()})

It would be great if someone can help me to complete my
dict.
thank you


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

limit_choices_to
user name
2006-03-26 20:01:30
I think that this http://
lukeplant.me.uk/blog.php?id=1107301634 might
be helpful. There's also been some traffic on
limit_choices_to in the
group recently (although not strictly relevent to your
problem I think)

Cheers,
Tone


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

limit_choices_to
user name
2006-03-27 13:54:58
Hello tonemcd,

Thank you for the link it look interesting.
However I am not understanding where I should add those
lines:
# cciw/middleware/threadlocals.py
import threading

_thread_locals = threading.local()

def get_current_user():
    try:
        return _thread_locals.user
    except AttributeError:
        return None

class ThreadLocals(object):
    """Middleware that adds various
objects to thread local storage
from the request object."""
    def process_request(self, request):
        _thread_locals.user = getattr(request, 'user',
None)

Do you have an idea?

Thank you


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

limit_choices_to
user name
2006-03-27 14:17:28
Well Luke (the author) might have a better idea than me, but
I'll have
a go ;)

Put it anywhere in your applications folder structure, Luke
chose
cciw/middleware because his app is called 'cciw' - but it
doesn't
matter because in his model file, he has the following...

..
...
import cciw.middleware.threadlocals

class ApplicationAdminOptions(AdminOptions):
....
..

Now,I haven't used this mind, so no gaurantees it will
work, but as
Luke is one of the core django developers, there's a better
than evens
chance that it will ;)

Cheers,
Tone


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

limit_choices_to
user name
2006-03-29 22:48:03
On Sunday 26 March 2006 21:01, tonemcd wrote:

> I think that this http://
lukeplant.me.uk/blog.php?id=1107301634 might
> be helpful. There's also been some traffic on
limit_choices_to in the
> group recently (although not strictly relevent to your
problem I
> think)

Note that this blog entry assumes magic-removal.  I think
the middleware 
bit should work in trunk, but I don't know.  In your
situation (yml), I 
think you need to create some kind of 'LazyUser' object in
the style of 
LazyDate.  The LazyUser object would use my
get_current_user() 
function.  Implementation is left as an exercise for the
reader 

Also, re: limit_choices_to - it wasn't working on m-r until
r2547 (March 
22), but it should be fixed now.

Regards,

Luke

-- 
"A man in love is incomplete until he is married. Then
he is finished." 
-- Zsa Zsa Gabor, "Newsweek"

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )