def add_metadata(self, key, metadata): self.init_metadata() meta = Metadata() meta.meta.id = key meta.meta.index = self.index meta.update_all(metadata) meta.save(using=self.connection)
def _get_metadata(self, key): """ Attempts to get existing metadata and creates one if it does not exist. Args: key(string): Unique key that represents the unique id of the metadata document. Returns: pyshelf.search.metadata.Metadata """ meta_doc = Metadata.get(id=key, index=self.index, using=self.connection, ignore=404) if not meta_doc: meta_doc = Metadata() meta_doc.meta.id = key meta_doc.meta.index = self.index return meta_doc