def get_field_info(model): """ A bypass of DRF's model_meta function, customized to work with our custom FieldInfo tuple. Some minor optimizations as well. """ # Bypass the concrete model fetch, as abstract (embedded) models lack it opts = get_model_meta(model) # Bypass for pk fetching for EmbeddedModels, as they do not have a pk if model_meta.is_abstract_model(model): pk = None else: pk = model_meta._get_pk(opts) # Fetch field info based on the model's options fields, fwd_relations, emb_fields = _build_generic_field_info(opts) rvs_relations = _build_reverse_field_info(opts) fields_and_pk = _merge_fields_and_pk(pk, fields) relations = _merge_relations(fwd_relations, rvs_relations) return FieldInfo( pk=pk, fields=fields, forward_relations=fwd_relations, reverse_relations=rvs_relations, embedded=emb_fields, fields_and_pk=fields_and_pk, relations=relations, )
def coerce_path(self, path, method, view): # TODO Handle versioning properly if '{version}' in path: path = path.replace('{version}', 'v1') if '{pk}' not in path: return path model = getattr(getattr(view, 'queryset', None), 'model', None) if model: field_name = _get_pk(model._meta.concrete_model._meta).name else: field_name = 'id' return path.replace('{pk}', '{%s}' % field_name)
def get_pk_name(model): meta = model._meta.concrete_model._meta return _get_pk(meta).name
def get_pk_name(model): meta = model._meta.concrete_model._meta return _get_pk(meta).name
def _pk_field_name(self): meta = self.Meta.model._meta return model_meta._get_pk(meta).name
def _pk_field_name(self): meta = self.Meta.model._meta return model_meta._get_pk(meta).name