Hi,

I'm customizing the django admin and I need to do a particular filter
for a foreign key if I'm modifying a model, I'm using the following
method, it works but it seems to me an hack, is there a better way to
do the same thing?

def formfield_for_foreignkey(self, db_field, request, **kwargs):
                if db_field.name == "domain":
                        mod=False
                        ID=-1
                        for val in request.path.split('/'):
                                try:
                                        ID=int(val)
                                        mod=True
                                        break
                                except:
                                        pass
                        if mod:
                                m_user=MailUser.objects.get(pk=ID)
                                kwargs["queryset"] = 
Domain.objects.filter(id=m_user.domain_id)
                        ......
                        return db_field.formfield(**kwargs)
                .............

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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