本文整理汇总了Python中user.models.User.get_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_or_create方法的具体用法?Python User.get_or_create怎么用?Python User.get_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.models.User
的用法示例。
在下文中一共展示了User.get_or_create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create [as 别名]
def _add(self, user_id):
if user_id not in self._nodes:
from user.models import User
with db.session():
self._nodes[user_id] = Node(self, User.get_or_create(user_id))
else:
if not self._nodes[user_id].online:
self._nodes[user_id].ping()
示例2: create_default_lists
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create [as 别名]
def create_default_lists(user_id=None):
with db.session():
user_id = user_id or settings.USER_ID
user = User.get_or_create(user_id)
user.update_name()
for list in settings.config['lists']:
l = List.get(user_id, list['title'])
if not l:
l = List.create(user_id, list['title'], list.get('query'))
示例3: restore
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create [as 别名]
def restore(cls, user_id, path=None):
from user.models import User
user = User.get_or_create(user_id)
if not path:
path = '/tmp/oml_changelog_%s.json' % user_id
with open(path, 'r') as fd:
for change in fd:
change = json.loads(change)
cls.apply_change(user, change, user_id == settings.USER_ID)
示例4: action_addpeer
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create [as 别名]
def action_addpeer(self, user, timestamp, peerid, username):
if len(peerid) == 16:
from user.models import User
if not 'users' in user.info:
user.info['users'] = {}
user.info['users'][peerid] = username
user.save()
peer = User.get_or_create(peerid)
if not 'username' in peer.info:
peer.info['username'] = username
peer.update_name()
peer.save()
return True
示例5: api_requestPeering
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_or_create [as 别名]
def api_requestPeering(user_id, username, message):
user = User.get_or_create(user_id)
if not user.info:
user.info = {}
if not user.peered:
if user.pending == 'sent':
user.info['message'] = message
user.update_peering(True, username)
user.update_name()
else:
user.pending = 'received'
user.info['username'] = username
user.info['message'] = message
user.update_name()
user.save()
trigger_event('peering.request', user.json())
return True
return False