Thanks.howerver, that is not i want.
I just want counter to record MyModel's number,so when a new entity is
saved the counter +1, and the above two operation should be in
transaction. And I just dont know how

On Jun 28, 9:16 pm, Emil Kjer <emil.k...@gmail.com> wrote:
> You need to reach the incremental method on the db object from a
> webapp.RequestHandler. From the 
> sourcehttp://google-app-engine-samples.googlecode.com/svn/trunk/sharded-cou...
> the counter-main-class is defined as:
>
> import generalcounter
> import simplecounter
>
> class CounterHandler(webapp.RequestHandler):
>   """Handles displaying the values of the counters
>   and requests to increment either counter.
>   """
>
>   def get(self):
>     template_values = {
>       'simpletotal': simplecounter.get_count(),
>       'generaltotal': generalcounter.get_count('FOO')
>     }
>     template_file = os.path.join(os.path.dirname(__file__),
> 'counter.html')
>     self.response.out.write(template.render(template_file,
> template_values))
>
>   def post(self):
>     counter = self.request.get('counter')
>     if counter == 'simple':
>       simplecounter.increment()
>     else:
>       generalcounter.increment('FOO')
>     self.redirect("/")
>
> So just make a post like the example eg. the simple counter:
>     <form action="" method="post">
>       <p><input type="hidden" name="counter" value="simple" /></p>
>
>       <p><input type="submit" value="Increment Simple" /></p>
>     </form>
>
> And rewrite your class to your purpose by following the counter-
> example. If it to any help this i the 
> sourcehttp://google-app-engine-samples.googlecode.com/svn/trunk/sharded-cou...
>
> Did that make sence? :)
>
> On Jun 28, 8:13 am, xiaojay <xiao...@gmail.com> wrote:
>
> > Hi guys,
>
> > I am new to gae and knew count() only return the exact num only when
> > the num is less than 1000
> > and I read the article about sharded counter
> > here:http://code.google.com/intl/en/appengine/articles/sharding_counters.html.
>
> > so I start to use it in my own project
> > like this:
>
> > import counter
> > class MyModel(db.Model):
> >   name = db.StringProperty()
>
> > #overwrite put so when new one is saved, counter + 1
> > def put(self):
> >     def txn():
> >            counter.increment('MyModel')
> >            return super(Mymodel, self).put()
> >     return db.run_in_transaction(txn)
>
> > howerver, when I test this code, get a error "BadRequestError: Nested
> > transactions are not supported.
> > "
> > I know why. howerver, i can not figure out how to go through it
> > beacuse i want save a entity and increase counter in a transaction
>
> > any ideas?
> > Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to