You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Author(models.Model):
name = models.CharField(max_length=30)
class Article(models.Model):
name = models.CharField(max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
Documents:
@registries.registry.register_document
class AuthorDocument(Document):
class Index:
name = 'author'
class Django:
model = models.Author
fields = ['name']
@registries.registry.register_document
class ArticleDocument(Document):
author = fields.ObjectField(doc_class=AuthorDocument)
class Index:
name = 'article'
class Django:
model = models.Article
fields = ['name']
Create and index article without tags:
art = Article(name="article 1")
art.tag_set # returns None
# call index logic
For such records we'll get structure to serialize in elasticsearch:
{
"name": "article 1",
"tag": {},
}
The main question is why do you return {} instead of None in get_value_from_instance and because of this the field is indexed as {} instead of None?
Django orm returns None in such cases. Maybe better to have similar behavior with Django here? Because difference in concepts breaks some serializer logic: when i use another serializer as serializer field, it tries to serialize related object(when it doesn't exists but elasticsearch returns {}) and i get error because {} doesn't have any fields
The text was updated successfully, but these errors were encountered:
Example structure:
Models:
Documents:
Create and index article without tags:
For such records we'll get structure to serialize in elasticsearch:
The main question is why do you return
{}
instead ofNone
inget_value_from_instance
and because of this the field is indexed as{}
instead ofNone
?Django orm returns
None
in such cases. Maybe better to have similar behavior with Django here? Because difference in concepts breaks some serializer logic: when i use another serializer as serializer field, it tries to serialize related object(when it doesn't exists but elasticsearch returns{}
) and i get error because{}
doesn't have any fieldsThe text was updated successfully, but these errors were encountered: