Get the primary key field value for a model instance.

        :param instance: The model instance to get the primary key for.
        :type instance: Model
        :return: The primary key value of the given model instance.
174015
def _get_pk_value(self, instance):
        
        pk_field = instance._meta.pk.name
        pk = getattr(instance, pk_field, None)

        # Check to make sure that we got an pk not a model object.
        if isinstance(pk, models.Model):
            pk = self._get_pk_value(pk)
        return pk
1018910
def fetch(self):
        
        params = values.of({})

        payload = self._version.fetch(
            'GET',
            self._uri,
            params=params,
        )

        return FieldValueInstance(
            self._version,
            payload,
            assistant_sid=self._solution['assistant_sid'],
            field_type_sid=self._solution['field_type_sid'],
            sid=self._solution['sid'],
        )
234422
def get(self, instance, aslist=False, **kwargs):
        
        refs = self.get_versioned_references_for(instance)

        if not self.multiValued:
            if len(refs) > 1:
                logger.warning("Found {} references for non-multivalued "
                               "reference field '{}' of {}".format(
                                   len(refs), self.getName(), repr(instance)))
            if not aslist:
                if refs:
                    refs = refs[0]
                else:
                    refs = None

        if not self.referencesSortable or not hasattr(
                aq_base(instance), "at_ordered_refs"):
            return refs

        refs = instance.at_ordered_refs
        order = refs[self.relationship]
        if order is None:
            return refs

        by_uid = dict(map(lambda ob: (api.get_uid(ob), ob), refs))
        return [by_uid[uid] for uid in order if uid in by_uid]
515030
def get_instance_by_slug(model, slug, **kwargs):
    
    try:
        model = get_model(model)
    except ImportError:
        return None

    query_params = dict(kwargs)
    query_params['slug'] = slug

    return model.query.filter_by(**query_params).first()
655676
def _key(self):
        
        return Key(self._schema.key_type, self._identity, self._name,
                   [str(item.value) for item in self._dimension_fields.values()])
1363957
def get_field_from_model_by_name(model_class, field_name):
    
    return first_match(lambda x: x if x.name == field_name else None, model_class._meta.fields)
567702
def to_instances(records)
      records.each_with_object({}) do |attributes, memo|
        record = @klass.new(attributes)
        memo[record[@klass.masterman.primary_key]] = record
      end
    end
292624
def get_value(self, instance):
        
        return instance.values.get(self.alias, self.default)
1173528
async def create_or_get(self, model_, **kwargs):
        
        try:
            return (await self.create(model_, **kwargs)), True
        except IntegrityErrors:
            query = []
            for field_name, value in kwargs.items():
                field = getattr(model_, field_name)
                if field.unique or field.primary_key:
                    query.append(field == value)
            return (await self.get(model_, *query)), False
358507
def _get(self, instance, **kw):
        
        logger.debug("DexterityFieldManager::get: instance={} field={}"
                     .format(instance, self.field))

        # TODO: Check security on the field level
        return self.field.get(instance)
46243
def get_instance_field(self, field_name):
        
        try:
            field = super(ModelWithDynamicFieldMixin, self).get_instance_field(field_name)
        except AttributeError:
            # the "has_field" returned True but getattr raised... we have a DynamicField
            dynamic_field = self._get_dynamic_field_for(field_name)  # it's a model bound field
            dynamic_field = self.get_field(dynamic_field.name)  # we now have an instance bound field
            field = self._add_dynamic_field_to_instance(dynamic_field, field_name)

        return field
437337
def id_field_name(cls):
        
        if cls._cache_id_field_name is None:
            pk_names = cls.pk_names()
            if len(pk_names) == 1:
                cls._cache_id_field_name = pk_names[0]
            else:  # pragma: no cover
                raise ValueError(
                    "{classname} has more than 1 primary key!"
                    .format(classname=cls.__name__)
                )
        return cls._cache_id_field_name
564987
def get(self):
        
        if not hasattr(self, '_instance'):
            raise ImplementationError("Impossible to get the PK of an unbound field")
        if not hasattr(self._instance, '_pk'):
            raise DoesNotExist("The current object doesn't exists anymore")

        if not self._instance._pk:
            self.set(value=None)

        return self.normalize(self._instance._pk)
187047
def from_key(cls, *args):
        
        key = args if len(args) > 1 else args[0]
        return cls._instances.get(key, None)
357208
def primary_key(self):
    
    pkname = self.primary_key_name
    if pkname is None:
      return None
    elif isinstance(pkname, str):
      return getattr(self, pkname)
    else:
      return tuple((getattr(self, pkn) for pkn in pkname))
1347596
function(instances) {
    var queryKey = this.foreignKey;
    var pks = _.map(instances, this.primaryKey);

    if (instances.length === 1) { pks = pks[0]; }
    else { queryKey += '$in'; }

    var where = _.object([[queryKey, pks]]);
    return this._relatedModel.objects.where(where);
  }
277018
public static Object getValue(Object instance, String fieldName) {
      Field f = findFieldRecursively(instance.getClass(), fieldName);
      if (f == null) throw new CacheException("Could not find field named '" + fieldName + "' on instance " + instance);
      try {
         f.setAccessible(true);
         return f.get(instance);
      } catch (IllegalAccessException iae) {
         throw new CacheException("Cannot access field " + f, iae);
      }
   }