MCPcopy Create free account
hub / github.com/django-haystack/django-haystack / get_fields

Method get_fields

haystack/indexes.py:509–548  ·  view source on GitHub ↗

Given any explicit fields to include and fields to exclude, add additional fields based on the associated model.

(self, fields=None, excludes=None)

Source from the content-addressed store, hash-verified

507 return f.name
508
509 def get_fields(self, fields=None, excludes=None):
510 """
511 Given any explicit fields to include and fields to exclude, add
512 additional fields based on the associated model.
513 """
514 final_fields = {}
515 fields = fields or []
516 excludes = excludes or []
517
518 for f in self.model._meta.fields:
519 # If the field name is already present, skip
520 if f.name in self.fields:
521 continue
522
523 # If field is not present in explicit field listing, skip
524 if fields and f.name not in fields:
525 continue
526
527 # If field is in exclude list, skip
528 if excludes and f.name in excludes:
529 continue
530
531 if self.should_skip_field(f):
532 continue
533
534 index_field_class = index_field_from_django_field(f)
535
536 kwargs = copy.copy(self.extra_field_kwargs)
537 kwargs.update({"model_attr": f.name})
538
539 if f.null is True:
540 kwargs["null"] = True
541
542 if f.has_default():
543 kwargs["default"] = f.default
544
545 final_fields[f.name] = index_field_class(**kwargs)
546 final_fields[f.name].set_instance_name(self.get_index_fieldname(f))
547
548 return final_fields

Callers 1

__init__Method · 0.95

Calls 6

should_skip_fieldMethod · 0.95
get_index_fieldnameMethod · 0.95
has_defaultMethod · 0.80
set_instance_nameMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected