Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update a model but return unmodified model in Django?
    text
    copied!<p>I'm using <a href="https://bitbucket.org/jespern/django-piston/wiki/Home" rel="nofollow">django-piston</a> to write a RESTful Web Service and have a problem.</p> <p>in models.py:</p> <pre><code>class Status(models.Model): user = models.ForeignKey(User) content = models.TextField(max_length=140) class StatusReply(models.Model): user = models.ForeignKey(User) reply_to = models.ForeignKey(Status, related_name='replies') content = models.TextField(max_length=140) has_read = models.BooleanField(default=False, help_text="has the publisher of the status read the reply") </code></pre> <p>in handlers.py:</p> <pre><code>class StatusHandler(BaseHandler): allowed_methods = ('GET', 'POST', 'DELETE' ) model = Status fields = ('id', ('user', ('id', 'username', 'name')), 'content', ('replies', ('id', ('user', ('id', 'username', 'name')), 'content', 'has_read'), ), ) @need_login def read(self, request, id, current_user): # the current_user arg is an instance of user created in @need_login try: status = Status.objects.get(pk=id) except ObjectDoesNotExist: return rc.NOT_FOUND else: if status.user == current_user: #if current_user is the publisher of the status, set all replies read status.replies.all().update(has_read=True) return status </code></pre> <p>In the handler, it returned a specific status by id. Now I want to return the status before <code>status.replies.all().update(has_read=True)</code> but also do the update operation in database. How to do it? Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload