Re: referencing the current instance inside limit_choices_to

2008-12-10 Thread bruno desthuilliers

On 10 déc, 19:25, fiedzia <[EMAIL PROTECTED]> wrote:
> On Dec 10, 1:56 am, GuyBowden <[EMAIL PROTECTED]> wrote:
>
> > I'd like to set the limit_choices_to value of a ForeignKey field based
> > on another selection in the current instance.
>
(snip)
>
> other thing to look at is that what is passed to limit_choices_to
> might be a callable,
> but it doesn't receive instance as parameter (and i would like it
> did).

I had a quick look, and it seems that limit_choices_to doesn't accept
a callable (at least in the svn version I use at work, rev 9100 iirc).
It can be a queryset or any object having a add_to_query(sqlquery)
method, but I failed to find any object implementing this protocol in
django itself, nor any documentation.


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



Re: referencing the current instance inside limit_choices_to

2008-12-10 Thread fiedzia

On Dec 10, 1:56 am, GuyBowden <[EMAIL PROTECTED]> wrote:

> I'd like to set the limit_choices_to value of a ForeignKey field based
> on another selection in the current instance.

Perhaps someone will come with better idea,
but for now to achieve this result i am modifying queryset in form
derived from model:


class SomeEditForm(ModelForm):
class Meta:
model = my_models.MyModel

def __init__(self,  *args,  **kwargs):
self.fields['author'].queryset =
my_models.MyModel.objects.filter(user=self.tied_user)


other thing to look at is that what is passed to limit_choices_to
might be a callable,
but it doesn't receive instance as parameter (and i would like it
did).


--
Maciej "Fiedzia" Dziardziel
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: referencing the current instance inside limit_choices_to

2008-12-10 Thread GuyBowden

Thankyou - saves me searching down this dead end...

Cheers,

Guy

On Dec 10, 7:54 am, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
> There is no way to have per-instance limit_choices_to.
>
> On Wed, Dec 10, 2008 at 03:56, GuyBowden <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I've looked about but can't find the answer to this.
>
> > I'd like to set the limit_choices_to value of a ForeignKey field based
> > on another selection in the current instance.
>
> > i.e. - filter the choices based on another field of the same instance.
>
> > something like this:
>
> > my_fk.limit_choices_to = my_fk.objects.get(Q(type = self.fk_type))
>
> > but that fails as self is not defined by then obviously...
>
> > 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
-~--~~~~--~~--~--~---



Re: referencing the current instance inside limit_choices_to

2008-12-09 Thread Alex Koshelev
There is no way to have per-instance limit_choices_to.


On Wed, Dec 10, 2008 at 03:56, GuyBowden <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I've looked about but can't find the answer to this.
>
> I'd like to set the limit_choices_to value of a ForeignKey field based
> on another selection in the current instance.
>
> i.e. - filter the choices based on another field of the same instance.
>
> something like this:
>
> my_fk.limit_choices_to = my_fk.objects.get(Q(type = self.fk_type))
>
> but that fails as self is not defined by then obviously...
>
> 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
-~--~~~~--~~--~--~---