I am using django-piston to write RESTful web service and problems.
in models.py:
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")
in handlers.py:
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):
try:
status = Status.objects.get(pk=id)
except ObjectDoesNotExist:
return rc.NOT_FOUND
else:
if status.user == current_user:
status.replies.all().update(has_read=True)
return status
In the handler, it returns a specific status by id. Now I want to return the status to status.replies.all().update(has_read=True), and also perform an update operation in the database. How to do it? Thanks in advance.
source
share