django-elasticsearch-dsl icon indicating copy to clipboard operation
django-elasticsearch-dsl copied to clipboard

Allow prepare_field for nested objects in an object field

Open ETinLV opened this issue 5 years ago • 5 comments

I need a prepare method on the field inside a Object field. It would be really nice if I could just use double underscore notation and just create a prepare method.

Something like this:

class CarDocument(DocType):
    model = fields.ObjectField(properties={
        'make': fields.KeywordField(),
    }),

@staticmethod
def prepare_model__make(instance):
    #doing things here would be nice!

ETinLV avatar Aug 13 '19 21:08 ETinLV

Are there any updates regarding this? How did you manage to prepare model.make?

quiin avatar Sep 25 '19 16:09 quiin

Why dont you just prepare the objectfield and return the value as dictionary? something like

def prepare_model(self, instance):
    return {"make": instance.model.make}

safwanrahman avatar Oct 31 '19 18:10 safwanrahman

I ended up doing that, @safwanrahman I just think it'd be cool to have support for specific nested fields

quiin avatar Nov 02 '19 00:11 quiin

Any Updates?

Vikku14 avatar Feb 20 '22 14:02 Vikku14

@Vikku14 have you found a workaround for this please?

MurphyAdam avatar Mar 18 '22 14:03 MurphyAdam