Instance of :attr:`model_type` with id :attr:`object_id`.
497487
def object(self, session):
        ''''''
        if not hasattr(self, '_object'):
            pkname = self.model_type._meta.pkname()
            query = session.query(self.model_type).filter(**{pkname:
                                                             self.object_id})
            return query.items(callback=self.__set_object)
        else:
            return self._object
50380
def get_templatetype(type_id,**kwargs):
    

    templatetype = db.DBSession.query(TemplateType).filter(
                        TemplateType.id==type_id).options(
                        joinedload_all("typeattrs")).one()

    return templatetype
882456
def attr(cls, iterable, attr_name):
    

    return cls(getattr(x, attr_name) for x in iterable)
232999
def get_model(obj):
    
    p = obj
    while hasattr(p, 'parent'):
        p = p.parent
    return p
699019
def database_add_types(object_id, input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/%s/addTypes' % object_id, input_params, always_retry=always_retry, **kwargs)
195154
def get_object_example(self, def_name):
        '''
        
        '''
        def_model = self.definitions[def_name]
        example = dict()
        for opt_name, opt_value in def_model.get('properties', dict()).items():
            var_type = opt_value.get('format', None) or opt_value.get('type', None)
            example[opt_name] = self.get_response_example(opt_name, var_type, opt_value)
            if var_type == 'string':
                example[opt_name] = example[opt_name].format(opt_name)
        return example
1306633
def get_or_exception(cls, id):
        '''  '''
        obj = cls.get(id)

        if obj is None:
            raise ModelNotFoundError('This object does not exist in database')

        return obj
201805
def type_and_model_to_query(self, request):
        
        try:
            content_type_id = request.GET["content_type_id"]
            object_id = request.GET["object_id"]
        except KeyError:
            return HttpResponseBadRequest()

        try:
            content_type = ContentType.objects.get(pk=content_type_id)
            model = content_type.model_class()
            result = model.objects.get(pk=object_id)
        except ObjectDoesNotExist:
            data = ""
        else:
            data = '%s: "%d: %s"' % (content_type.model, result.pk, result)

        return JsonResponse({"query": data})
695158
def get_objects_with_attribute(self, obj_type, attribute, value):
        
        return [o for o in self.get_objects_by_type(obj_type) if o.get_attribute(attribute) == value]
753377
def _ensure_object_id(cls, id):
        """"""
        if isinstance(id, ObjectId):
            return id

        if isinstance(id, basestring) and OBJECTIDEXPR.match(id):
            return ObjectId(id)

        return id
632518
def class_for_type(self, object_type):
        
        if object_type not in self.class_mapping:
            raise ZenpyException("Unknown object_type: " + str(object_type))
        else:
            return self.class_mapping[object_type]
339773
def to_model(cls, value):
    

    if isinstance(value, cls) or value is None:
        pass  # skip if right type or value is None

    elif issubclass(cls, Enum):
        value = cls(value)

    elif is_model(cls) and isinstance(value, dict):
        value = convert_key_to_attr_names(cls, value)
        value = cls(**value)

    else:
        value = cls(value)

    return value
744426
def create_attribute_model(self, initial_value=None):
        # type: (Any) -> AttributeModel
        
        attr = self.attribute_class(meta=self, value=initial_value)
        return attr
719181
def app_model_id(obj):
    
    ct = ContentType.objects.get_for_model(obj)

    return '%s-%s-%s' % (ct.app_label, ct.model, obj.id)
958905
def convert_id_to_model(value, parameter):
    '''
    
    '''
    value = _check_default(value, parameter, ( '', '-', '0', None ))
    if isinstance(value, (int, str)):  # only convert if we have the id
        try:
            return parameter.type.objects.get(id=value)
        except (MultipleObjectsReturned, ObjectDoesNotExist) as e:
            raise ValueError(str(e))
    return value
1355470
def update(self, id, **kwargs):
        

        response = self.ghost.execute_put('%s/%s/' % (self._type_name, id), json={
            self._type_name: [
                kwargs
            ]
        })

        return self._model_type(response.get(self._type_name)[0])
23189
def find_or_new(self, id, columns=None):
        
        if columns is None:
            columns = ['*']

        instance = self.find(id, columns)

        if instance is None:
            instance = self._related.new_instance()
            self._set_foreign_attributes_for_create(instance)

        return instance