I think i solved it. This is the chain of method calls of admin.ModelAdmin:

...
change_view
  get_form
     formfield_for_foreignkey
...

get_form receives the current object as parameter, so all I had to do was to
inject obj in the request:

    def get_form(self, request, obj=None, **kwargs):
        request.obj = obj
        return super(AuthorContenidoAdmin, self).get_form(request, obj,
**kwargs)

and retrieve it later in formfield_for_foreignkey:

    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        obj = request.obj
        if db_field.name == 'status' and obj is not None:
            allowed_states = [t.destination for t in
 get_allowed_transitions(obj,request.user)]
            kwargs['queryset'] = FakeQueryset([get_state(obj)] +
 allowed_states)
        return super(AuthorContenidoAdmin,
self).formfield_for_foreignkey(db_field, request, **kwargs)



Regards,

  Juan Pablo

2011/5/5 Daniel Roseman <dan...@roseman.org.uk>

> On Thursday, May 5, 2011 10:32:47 PM UTC+1, juanpa wrote:
>>
>> Hello,
>>
>> Is it possible to obtain a reference to the modified object
>> in ModelAdmin.formfield_for_foreignkey?
>>
>> Thanks!
>>
>>    Juan Pablo
>>
>
> What do you mean, modified? formfield_for_foreignkey is used for defining
> the form, long before any modifications take place.
> --
> DR.
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to