'Returns a dictionary of all the fields on the resource and some
properties about those fields.
Used by the ``schema/`` endpoint to describe what will be available.'

def build_schema(self):

    data = {u'fields': {}, u'default_format': self._meta.default_format, u'allowed_list_http_methods': self._meta.list_allowed_methods, u'allowed_detail_http_methods': self._meta.detail_allowed_methods, u'default_limit': self._meta.limit}
    if self._meta.ordering:
        data[u'ordering'] = self._meta.ordering
    if self._meta.filtering:
        data[u'filtering'] = self._meta.filtering
    try:
        pk_field_name = self._meta.queryset.model._meta.pk.name
    except AttributeError:
        pk_field_name = None
    for (field_name, field_object) in self.fields.items():
        data[u'fields'][field_name] = {u'default': field_object.default, u'type': field_object.dehydrated_type, u'nullable': field_object.null, u'blank': field_object.blank, u'readonly': field_object.readonly, u'help_text': field_object.help_text, u'unique': field_object.unique, u'primary_key': (True if (field_name == pk_field_name) else False), u'verbose_name': (field_object.verbose_name or field_name.replace(u'_', u'    '))}
        if (field_object.dehydrated_type == u'related'):
            if field_object.is_m2m:
                related_type = u'to_many'
            else:
                related_type = u'to_one'
            data[u'fields'][field_name][u'related_type'] = related_type
            try:
                uri = self._build_reverse_url(u'api_get_schema', kwargs={u'api_name': self._meta.api_name, u'resource_name': field_object.to_class()._meta.resource_name})
            except NoReverseMatch:
                uri = u''
            data[u'fields'][field_name][u'related_schema'] = uri
    return data
