Evening all,

I was looking at filterspecs last night because I was trying to see if
RelatedFilterSpec could display the field's verbose name and not the
relation's meta verbose_name (ala f.rel.to._meta.verbose_name). So
poking around in the source for a while I came up with the following
solution:

class m2m_with_verbose_name_spec(RelatedFilterSpec):
    def __init__(self, f, request, params, model):
        super(m2m_with_verbose_name_spec, self).__init__(f, request,
params, model)
        if isinstance(f, models.ManyToManyField) and hasattr(f,
'verbose_name'):
            self.lookup_title = f.verbose_name
        else:
            self.lookup_title = f.rel.to._meta.verbose_name

filter_specs = copy(FilterSpec.filter_specs)
FilterSpec.filter_specs = [(lambda f: bool(hasattr(f, 'verbose_name')
and f.rel), m2m_with_verbose_name_spec)] + filter_specs

I'd like some feedback on if this is just a kludge or if there is a
more elegant way of pulling this off or if I should just stuff it. The
nastiness is getting my m2m function to come BEFORE RelatedFilterSpec,
so one solution to this is shown above. I also patched FilterSpec's
register method to have push like functionality so user registered
functions are evaluated before the ones included with FilterSpec, but
at the moment I do not want to rely on modifying the django source, but
am willing to send this patch in to be reviewed and write up
documentation on writing custom filter specs.

 If I'm on to something shall we discuss?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to