[Answer]-Haystack indexing related model issue

1👍

self.related.model.DoesNotExist means that there is no Parts instance for the Main object that haystack is indexing at the time of the error. You can catch the exception and just return an empty string "" in that case:

# ...
def prepare_parts(self, obj):
    try:
        return obj.mainparts.parts
    except Parts.DoesNotExist:
        return ""
# ...
👤sk1p

Leave a comment