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
I tried this, which tells me "illegal argument exceptions":
documents.py
from django_elasticsearch_dsl import DocType, Index, fields
from .models import Item
item = Index('items')
item.settings(
number_of_shards=1,
number_of_replicas=0
)
@item.doc_type
class ItemDocument(DocType):
tag = fields.StringField(attr="get_grouped_tags")
class Meta:
model = Item
fields = [
'typetask',
'title',
]
models.py
class Tag(models.Model):
name = models.CharField("Name", max_length=5000, blank=True)
taglevel = models.IntegerField("Tag level", null=True, blank=True)
def to_search(self):
tags = self.id
if tags:
queryset = Item.objects.filter(tag=tags)
for object in queryset:
object.save()
return queryset
class Item(models.Model):
title = models.CharField("Title", max_length=10000, blank=True)
tag = models.ManyToManyField('Tag', blank=True)
def get_grouped_tags(self):
tag = self.tag.order_by('taglevel')
grouped_tags = {
tag_level: [
{ 'name': tag_of_level.name, 'taglevel': tag_of_level.taglevel, }
for tag_of_level in tags_of_level
] for tag_level, tags_of_level
in groupby(tag, lambda tag: tag.taglevel)
}
return grouped_tags
I tried tag = fields.NestedField(attr="get_grouped_tags"), but the tags field just comes up empty in the index.
I tried:
tag = fields.NestedField(properties={
'name': fields.StringField(),
})
But that returns this traceback gave be a keyError for manager (http://dpaste.com/35D46HP). Also, even if this did work, the data would still need to be presented as it looks in my function.
How do I properly access my nested data from an M2M field?
Thanks
PS:
Could be good to tell newbies how to install it pip install git+https://github.com/sabricot/django-elasticsearch-dsl.git
The text was updated successfully, but these errors were encountered:
yarnball
changed the title
Accessing nested fields via a function
Accessing nested fields via a function (M2M)
Mar 18, 2017
Uh oh!
There was an error while loading. Please reload this page.
Great work on this!
I'm having trouble with my nested data.
Due to my front end, my data has to stay in a this layout/=format. The data (what
get_grouped_tags
) returns will look like this:I tried this, which tells me "illegal argument exceptions":
documents.py
models.py
I tried
tag = fields.NestedField(attr="get_grouped_tags")
, but thetags
field just comes up empty in the index.I tried:
But that returns this traceback gave be a keyError for manager (http://dpaste.com/35D46HP). Also, even if this did work, the data would still need to be presented as it looks in my function.
How do I properly access my nested data from an M2M field?
Thanks
PS:
Could be good to tell newbies how to install it
pip install git+https://github.com/sabricot/django-elasticsearch-dsl.git
The text was updated successfully, but these errors were encountered: