I need to get a count of records for a particular Model on app engine. How does one do it?
I bulk uploaded more than 4000 records but modelname.count() only shows me 1000.
I need to get a count of records for a particular Model on app engine. How does one do it?
I bulk uploaded more than 4000 records but modelname.count() only shows me 1000.
As of release 1.3.6, there is no longer a cap of 1,000 on count queries. Thus you can do the following to get a count beyond 1,000:
count = modelname.all(keys_only=True).count()
This will count all of your entities, which could be rather slow if you have a large number of entities. As a result, you should consider calling count()
with some limit specified:
count = modelname.all(keys_only=True).count(some_upper_bound_suitable_for_you)
In GAE a count will always make you page through the results when you have more than 1000 objects. The easiest way to deal with this problem is to add a counter property to your model or to a different counters table and update it every time you create a new object.