Search code examples
pythongoogle-app-enginegoogle-cloud-datastorelistproperty

Access an item in ListProperty


I have a Model like below

class XXX(db.Model):
    f_list = db.ListProperty(int,indexed=True) #Store 50000 numbers

How to access the 3rd item in f_list?


Solution

  • You would use a standard list indexing operation to access the 3rd item in the list

    some_obj.f_list[2]
    

    However the entire entity will be loaded into memory when you fetch an instance of XXX

    There is no way around it with the model you have.

    Even a projection query will return the entire list.

    The only possibility would be to start creating multiple sub entities.