本文整理匯總了Python中server.models.User.objects方法的典型用法代碼示例。如果您正苦於以下問題:Python User.objects方法的具體用法?Python User.objects怎麽用?Python User.objects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類server.models.User
的用法示例。
在下文中一共展示了User.objects方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import objects [as 別名]
def post(self):
data = request.form
print data
if len(set(['name', 'cost', 'payer', 'buyins']) &
set([x for x in data])) == 4:
# Validate that users involved have accounts
# Extract payer id
payer = User.objects(username=data['payer'])
payer_id = payer[0].id
# Extract ids of those who buy in
buyins = User.objects(username__in=data['buyins'])
buyin_ids = map(lambda x: x.id, buyins)
purchase = Purchase(name=data['name'],
cost=data['cost'],
payer=payer_id,
buyins=buyin_ids,
time=datetime.datetime.now())
purchase.save()
debt_up_to_date = self.updateDebt(purchase)
return jsonify({'res': True,
'messsage': 'Purchase added',
'debts': debt_up_to_date})
return jsonify({'res': False,
'message': 'default'})
示例2: post
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import objects [as 別名]
def post(self):
try:
data = json.loads(self.request.body)
body = data['body']
name = data['chat_id']
username = data['username']
chat = Chat.objects(slug_name=name).get()
user = User.objects(username=username).get()
self.set_status(201)
message = Message(
from_user=user,
chat=chat,
created_at=datetime.now(),
body=body,
is_private=self.is_private
)
users = [user for user in chat.users]
if len(users) > 1:
to_user = users[random.randrange(0, len(users))]
while to_user.id == user.id:
to_user = users[random.randrange(0, len(users))]
message.to_user = to_user
message.save()
self.write(message.to_representation())
except (Chat.DoesNotExist, User.DoesNotExist):
self.clear()
self.set_status(404)
self.finish({'error': 'not found'})
示例3: clean
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import objects [as 別名]
def clean():
for message in Message.objects():
message.delete()
for user in User.objects():
user.delete()
for chat in Chat.objects():
chat.delete()
示例4: delete
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import objects [as 別名]
def delete(self, name):
self.set_status(204)
try:
chat = Chat.objects(slug_name=name).get()
data = json.loads(self.request.body)
username = data['username']
user = User.objects(username=username).get()
chat.update(pull__users=user)
chat.save()
except (Chat.DoesNotExist, User.DoesNotExist):
self.clear()
self.set_status(404)
self.finish({'error': 'not found'})
示例5: get
# 需要導入模塊: from server.models import User [as 別名]
# 或者: from server.models.User import objects [as 別名]
def get(self):
try:
username = self.get_argument('username')
user = User.objects(username=username).get()
last_date = self.get_argument('last_date', None)
if last_date:
last_date = datetime.strptime(last_date, '%Y-%m-%dT%H:%M:%S.%f')
messages = Message.objects(to_user=user, is_private=self.is_private,
created_at__gt=last_date).order_by('created_at')
else:
messages = Message.objects(to_user=user,
is_private=self.is_private).order_by('-created_at').limit(10)
messages = [message for message in messages]
messages.reverse()
self.write({'results': [message.to_representation() for message in messages]})
except (Chat.DoesNotExist, User.DoesNotExist):
self.clear()
self.set_status(404)
self.finish({'error': 'not found'})