Возвращает related_instance для эластичного поиска - PullRequest
0 голосов
/ 02 апреля 2019

У меня есть модель с именем Book and Author, Location, UserReadHistory as related_models. Мой models.py выглядит так,

class Author(TimeStamp):
    author = models.CharField(max_length=100, null=True, blank=True)
    location = models.ForeignKey(Location,on_delete=models.CASCADE,null=True,blank=True)

    def __unicode__(self):
        return "Author details: {}" .format(self.title)


class Location (TimeStamp):
    """Book model defined
    location  = models.CharField(max_length=100,null=True,blank=True)
    coordinate = models.IntegerField(null=True,blank=True)



class Book(TimeStamp):
    """Book model defined here"""
    title = models.CharField(max_length=100,null=True,blank=True)
    isbn = models.CharField(max_length=100,null=True,blank=True)
    category = models.CharField(max_length=100,null=True,blank=True)
    language = models.CharField(max_length=100,null=True,blank=True)
    price = models.IntegerField(null=True,blank=True)
    author = models.ForeignKey(Author,on_delete=models.CASCADE,null=True,blank=True)

мои документы.py похожи,

@book.doc_type
class BookDocument(DocType):

    #connecting book and author where author is foreign key of book
    author = fields.ObjectField(properties={
        'author': fields.StringField(),
        'country':fields.StringField()
    })

    class Meta:
        model = Book
        related_models = [Author,Location]
        fields = ['title', 'isbn', 'category', 'language','price']

def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, Author):
            return related_instance.author_set.all()
        elif isinstance(related_instance, Location):
            return related_instance.location_set.all()


Поэтому, когда я пытаюсь обновить Author, я получаю сообщение об ошибке,

'Author' object has no attribute 'author_set'

Как мне написать свое заявление о возврате так, чтобы оно обновляло мой эластичный поиск

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...