I've a model MyModel (extending Google's db.Model), and I want to keep track of the number of Models that have been created.
I think the code at from Google's I/O talk on Sharding Counters is quite good, so I'm using that. But I'm not sure where I ought to be calling the increment when creating a new code. (I'm using Django, and I've kept the familiar models.py, views.py, etc. layout to the project's applications.)
There are a couple possibilities that seem to come to mind for where to put the incrementing code:
Overload the Model.put() so that it increments the counter when the model is saved for the first time, and similarly overload Model.delete() to decrement the counter
Attach some sort of listener to saves/deletes, and check that the save is of a new model (does GAE have such listeners?)
Put the counter incrementing code in the function in view.py that creates/deletes models
I'd be much obliged for suggestions and thoughts as to how to do this best (and pros/cons of each option).
Thank you for reading.
Best, Brian