Where should I put the code for automatically creating a fragment counter in Google App Engine / Django when creating a new model?

I have a MyModel model (extending Google db.Model) and I want to track the number of models created.

I think the code from the Google I / O conversation on Sharding Counters is not bad, so I use this. But I'm not sure where I should call increment when creating new code. (I use Django, and I kept the familiar models.py models, views.py, etc. For project applications.)

There are a couple of possibilities that seem to come to mind where you can put incremental code:

  • Overload Model.put () so that it increments the counter when the model was first saved, and similarly overload Model.delete () to decrease the counter

  • Attach some kind of listener to the save / delete and check that the save has a new model (does GAE have such listeners?)

  • Put the counter increment code in a function in view.py that creates / removes models

I would be very grateful for suggestions and thoughts on how to do this best (and the pros / cons of each option).

Thanks for reading.

Best, Brian

+3
source share
1 answer

( "- " ), "App Engine Fan" ( " " ) ( : " ", "" App Engine).

"", , , - , "", (2), , "" "" ( , ), ( , "" , , put - , , ).

+2

Source: https://habr.com/ru/post/1716997/


All Articles