[Soc2014] Official meta API

Good question! Because m2m fields are hidden by default (they don't really
exist) so I first fetch all hidden reverse relations and then discard all
non m2m relations that are hidden.

On Thursday, September 4, 2014, Markus Holtermann <notifications@github.com>
wrote:

> In django/db/models/options.py:
>
> > -        Returns the requested field by name. Raises FieldDoesNotExist on error.
> > -        """
> > -        to_search = (self.fields + self.many_to_many) if many_to_many else self.fields
> > -        for f in to_search:
> > -            if f.name == name:
> > -                return f
> > -        raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, name))
> > +    @cached_property
> > +    def related_objects(self):
> > +        # This property contains all related objects pointing to the current model.
> > +        # The related objects can come from a one-to-one, one-to-many, many-to-many
> > +        # field relation type.
> > +        all_related_fields = self.get_fields(forward=False, reverse=True,
> > +                                             include_hidden=True, cache_results=True)
> > +        return [obj for obj in all_related_fields
> > +                if not obj.field.rel.is_hidden() or isinstance(obj.field, ManyToManyField)]
>
> Why do you use include_hidden=True two lines above and filter them out
> here?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/django/django/pull/3114/files#r17108227>.
>


-- 
*************

PirosB3

https://github.com/PirosB3