当前位置: 首页>>代码示例>>Python>>正文


Python shortcuts.model_to_dict方法代码示例

本文整理汇总了Python中playhouse.shortcuts.model_to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python shortcuts.model_to_dict方法的具体用法?Python shortcuts.model_to_dict怎么用?Python shortcuts.model_to_dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在playhouse.shortcuts的用法示例。


在下文中一共展示了shortcuts.model_to_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def update(self, fields_to_update=None):
        if not fields_to_update:
            fields_to_update = model_to_dict(self, recurse=False)

        model_id = fields_to_update['id']
        del fields_to_update['id']

        model_class = self.__class__

        query = super(PeeweeModel, self).update(**fields_to_update)
        query = query.where(model_class.id == model_id)
        query.execute()

        for field, value in fields_to_update.items():
            setattr(self, field, value)

        return self 
开发者ID:felipevolpone,项目名称:ray,代码行数:19,代码来源:all.py

示例2: _to_dict

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def _to_dict(self):
        data = {}
        fields = self.val._meta.fields
        for name, v in model_to_dict(self.val, recurse=False).items():
            if isinstance(fields[name], peewee.ForeignKeyField):
                name = name + '_id'
            elif isinstance(fields[name], peewee.BlobField):
                v = get_bytes_from_blob(v)
            if self.selected != ALL_COLUMNS and (self.selected and (name not in self.selected)):
                continue
            data[name] = v

        if self.available_columns != ALL_COLUMNS:
            return dict_filter(data, self.available_columns)

        return data 
开发者ID:fy0,项目名称:slim,代码行数:18,代码来源:data_record.py

示例3: handle_session

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def handle_session():
    uid = 0
    paths = request.path.split('/')
    if len(paths) > 1 and paths[1].isdigit():
        uid = int(paths[1])

    if 'user' in session and ((not uid) or (uid and session['user']['uid'] == uid)):
        g.user = session['user']
    elif uid:
        user = FetchedUser.get_or_none(FetchedUser.uid == uid)
        if not user:
            abort(404, "no such user")

        session['user'] = model_to_dict(user)
        g.user = session['user']
    else:
        g.user = None 
开发者ID:whusnoopy,项目名称:renrenBackup,代码行数:19,代码来源:web.py

示例4: get_data

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def get_data(self):
		if self.cache and self.advanced == self.cache_advanced:
			return self.cache

		self.fields, self.map_list, self.folder_info, self.folder_instance = \
			await self.folder_manager.get_folder_code_contents(self.folder_code)

		self.title = 'Folder: ' + self.folder_info['name']

		karma = any(f['index'] == "karma" for f in self.fields)
		length = any(f['index'] == "local_record" for f in self.fields)

		items = []
		for item in self.map_list:
			dict_item = model_to_dict(item)
			if length:
				dict_item['local_record'] = times.format_time((item.local['first_record'].score if hasattr(item, 'local') and item.local['first_record'] else 0))
			if karma and 'karma' in self.app.instance.apps.apps:
				dict_item['karma'] = (await self.app.instance.apps.apps['karma'].get_map_karma(item))['map_karma']
			items.append(dict_item)

		self.cache = items
		return self.cache 
开发者ID:PyPlanet,项目名称:PyPlanet,代码行数:25,代码来源:views.py

示例5: get_aircraft

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def get_aircraft(icao24):
    icao24 = icao24.lower()
    try:
        obj = Plane.get(icao24 = icao24)
    except Plane.DoesNotExist:
        abort(404)
    o = model_to_dict(obj)
    # model_to_dict does not format dates
    try:
        o['added_on'] = str(obj.added_on.strftime('%Y-%m-%d %H:%M:%S'))
    except AttributeError:
        # String is not a date string
        o['added_on'] = None
    try:
        o['updated_on'] = str(obj.updated_on.strftime('%Y-%m-%d %H:%M:%S'))
    except AttributeError:
        o['updated_on'] = None
    return o 
开发者ID:kanflo,项目名称:ADS-B-funhouse,代码行数:20,代码来源:planedb-serv.py

示例6: get_airport

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def get_airport(ica_or_iata):
    ica_or_iata = ica_or_iata.upper()
    try:
        obj = Airport.get(icao = ica_or_iata)
    except Airport.DoesNotExist:
        try:
            obj = Airport.get(iata = ica_or_iata)
        except Airport.DoesNotExist:
            abort(404)
    o = model_to_dict(obj)
    # model_to_dict does not format dates
    o['lat'] = "%f" % obj.lat
    o['lon'] = "%f" % obj.lon
    o['alt'] = "%d" % obj.alt
    o['added_on'] = str(obj.added_on.strftime('%Y-%m-%d %H:%M:%S'))
    o['updated_on'] = str(obj.updated_on.strftime('%Y-%m-%d %H:%M:%S'))
    return o 
开发者ID:kanflo,项目名称:ADS-B-funhouse,代码行数:19,代码来源:planedb-serv.py

示例7: get_airline

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def get_airline(icao):
    icao = icao.upper()
    try:
        obj = Airline.get(icao = icao)
    except Airline.DoesNotExist:
        abort(404)
    o = model_to_dict(obj)
    # model_to_dict does not format dates
    try:
        o['added_on'] = str(obj.added_on.strftime('%Y-%m-%d %H:%M:%S'))
    except AttributeError:
        # String is not a date string
        o['added_on'] = None
    try:
        o['updated_on'] = str(obj.updated_on.strftime('%Y-%m-%d %H:%M:%S'))
    except AttributeError:
        o['updated_on'] = None
    return o 
开发者ID:kanflo,项目名称:ADS-B-funhouse,代码行数:20,代码来源:planedb-serv.py

示例8: get_route

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def get_route(flight):
    flight = flight.upper()
    try:
        obj = Route.get(flight = flight)
    except Route.DoesNotExist:
        abort(404)
    o = model_to_dict(obj)
    # model_to_dict does not format dates
    try:
        o['added_on'] = str(obj.added_on.strftime('%Y-%m-%d %H:%M:%S'))
    except AttributeError:
        # String is not a date string
        o['added_on'] = None
    try:
        o['updated_on'] = str(obj.updated_on.strftime('%Y-%m-%d %H:%M:%S'))
    except AttributeError:
        o['updated_on'] = None
    return o 
开发者ID:kanflo,项目名称:ADS-B-funhouse,代码行数:20,代码来源:planedb-serv.py

示例9: post

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def post(self, request):
        valid_request = self.validate_request(request)

        if valid_request is not True:
            return valid_request

        try:
            result = self.model.create(**request.json)
            return self.response_json(data=model_to_dict(result),
                                      status_code=200,
                                      message=self.config.response_messages.SuccessRowCreated.format(result.id)
                                      )
        except Exception as e:
            log.error(traceback.print_exc())
            return self.response_json(message=str(e),
                                      status_code=500
                                      ) 
开发者ID:Typhon66,项目名称:sanic_crud,代码行数:19,代码来源:collection_resource.py

示例10: report

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def report(self, machine: GordoMachine):
        """
        Log a machine to Postgres where top level keys, 'name', 'dataset', 'model',
        and 'metadata' mappings to BinaryJSON fields.

        Parameters
        ----------
        machine: gordo.machine.Machine

        Returns
        -------
        None
        """
        try:
            with self.db.atomic():
                logger.info(f"Inserting machine {machine.name} in sql")  # type: ignore

                # Ensure it's serializable using MachineEncoder
                record = json.loads(json.dumps(machine.to_dict(), cls=MachineEncoder))
                model = dict_to_model(Machine, record, ignore_unknown=True)
                try:
                    Machine.get(Machine.name == machine.name)
                except peewee.DoesNotExist:
                    model.save()
                else:
                    query = Machine.update(**model_to_dict(model)).where(
                        Machine.name == machine.name
                    )
                    query.execute()

        except Exception as exc:
            raise PostgresReporterException(exc) 
开发者ID:equinor,项目名称:gordo,代码行数:34,代码来源:postgres.py

示例11: models_to_dicts

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def models_to_dicts(query_models):
    dict_list = []
    for query_model in query_models:
        dict_list.append(model_to_dict(query_model))
    return dict_list 
开发者ID:521xueweihan,项目名称:hellogithub.com,代码行数:7,代码来源:tools.py

示例12: search_project

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def search_project():
    project_url = request.args.get('project_url', '')
    if project_url:
        try:
            content = Content.select()\
                             .where(Content.project_url == project_url)\
                             .get()
            return jsonify(payload=model_to_dict(content))
        except DoesNotExist:
            return jsonify(message='未找到')
    else:
        raise InvalidParams() 
开发者ID:521xueweihan,项目名称:hellogithub.com,代码行数:14,代码来源:manage.py

示例13: to_json

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def to_json(self):
        return model_to_dict(self, recurse=False) 
开发者ID:felipevolpone,项目名称:ray,代码行数:4,代码来源:all.py

示例14: to_dict

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def to_dict(self):
        return model_to_dict(self) 
开发者ID:fy0,项目名称:fpage,代码行数:4,代码来源:__init__.py

示例15: to_dict

# 需要导入模块: from playhouse import shortcuts [as 别名]
# 或者: from playhouse.shortcuts import model_to_dict [as 别名]
def to_dict(self, **kw):
        return shortcuts.model_to_dict(self, **kw) 
开发者ID:Ehco1996,项目名称:aioshadowsocks,代码行数:4,代码来源:__init__.py


注:本文中的playhouse.shortcuts.model_to_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。