lamindb.base.fields.ForeignKey¶
- class lamindb.base.fields.ForeignKey(*args, **kwargs)¶
Bases:
ForeignKey
Custom
ForeignKey
with default values forblank
.Django default value for
ForeignKey
blank=False
.Attributes¶
- auto_creation_counter = -59¶
- property choices¶
- class_lookups = {'exact': <class 'django.db.models.fields.related_lookups.RelatedExact'>, 'gt': <class 'django.db.models.fields.related_lookups.RelatedGreaterThan'>, 'gte': <class 'django.db.models.fields.related_lookups.RelatedGreaterThanOrEqual'>, 'in': <class 'django.db.models.fields.related_lookups.RelatedIn'>, 'isnull': <class 'django.db.models.fields.related_lookups.RelatedIsNull'>, 'lt': <class 'django.db.models.fields.related_lookups.RelatedLessThan'>, 'lte': <class 'django.db.models.fields.related_lookups.RelatedLessThanOrEqual'>}¶
- creation_counter = 964¶
- property db_returning¶
Private API intended only to be used by Django itself.
- property db_tablespace¶
- default_error_messages = {'invalid': '%(model)s instance with %(field)s %(value)r does not exist.'}¶
- default_validators = []¶
- description = 'Foreign Key (type determined by related field)'¶
- descriptor_class = <class 'django.db.models.fields.related_descriptors.ForeignKeyDeferredAttribute'>¶
- empty_strings_allowed = False¶
- empty_values = [None, '', [], (), {}]¶
- property flatchoices¶
Flattened version of choices tuple.
- generated = False¶
- get_lookups = functools.partial(<functools._lru_cache_wrapper object>, <class 'lamindb.base.fields.ForeignKey'>)¶
- many_to_many = False¶
- many_to_one = True¶
- non_db_attrs = ('blank', 'choices', 'db_column', 'editable', 'error_messages', 'help_text', 'limit_choices_to', 'on_delete', 'related_name', 'related_query_name', 'validators', 'verbose_name')¶
- one_to_many = False¶
- one_to_one = False¶
- register_lookup = functools.partial(<function RegisterLookupMixin.register_class_lookup>, <class 'lamindb.base.fields.ForeignKey'>)¶
- rel_class = <class 'django.db.models.fields.reverse_related.ManyToOneRel'>¶
- requires_unique_target = True¶
- property swappable_setting¶
Get the setting that this is powered from for swapping, or None if it’s not swapped in / marked with swappable=False.
- system_check_deprecated_details = None¶
- system_check_removed_details = None¶
- property target_field¶
Class methods¶
- classmethod get_class_lookups()¶
- classmethod register_class_lookup(lookup, lookup_name=None)¶
Methods¶
- cast_db_type(connection)¶
- check(**kwargs)¶
- clone()¶
Uses deconstruct() to clone a new copy of this Field. Will not preserve any class attachments/attribute names.
- contribute_to_class(cls, name, private_only=False, **kwargs)¶
- convert_empty_strings(value, expression, connection)¶
- db_check(connection)¶
- db_parameters(connection)¶
- db_type(connection)¶
- db_type_parameters(connection)¶
- db_type_suffix(connection)¶
- deconstruct()¶
- delete_cached_value(instance)¶
- formfield(*, using=None, **kwargs)¶
- get_attname()¶
- get_attname_column()¶
- get_cache_name()¶
- get_cached_value(instance, default=<object object>)¶
- get_choices(include_blank=True, blank_choice=[('', '---------')], limit_choices_to=None, ordering=())¶
Return choices with a default blank choices included, for use as <select> choices for this field.
- get_col(alias, output_field=None)¶
- get_db_converters(connection)¶
- get_db_prep_save(value, connection)¶
- get_db_prep_value(value, connection, prepared=False)¶
- get_default()¶
Return the to_field if the default value is an object.
- get_extra_descriptor_filter(instance)¶
Return an extra filter condition for related object fetching when user does ‘instance.fieldname’, that is the extra filter is used in the descriptor of the field.
The filter should be either a dict usable in
.filter(**kwargs)
call or a Q-object. The condition will be ANDed together with the relation’s joining columns.A parallel method is get_extra_restriction() which is used in JOIN and subquery conditions.
- get_extra_restriction(alias, related_alias)¶
Return a pair condition used for joining and subquery pushdown. The condition is something that responds to as_sql(compiler, connection) method.
Note that currently referring both the ‘alias’ and ‘related_alias’ will not work in some conditions, like subquery pushdown.
A parallel method is get_extra_descriptor_filter() which is used in instance.fieldname related object fetching.
- get_filter_kwargs_for_object(obj)¶
Return a dict that when passed as kwargs to self.model.filter(), would yield all instances having the same value for this field as obj has.
Return the keyword arguments that when supplied to self.model.object.filter(), would select all instances related through this field to the remote obj. This is used to build the querysets returned by related descriptors. obj is an instance of self.related_field.model.
- get_instance_lookups()¶
- get_internal_type()¶
- get_joining_columns(reverse_join=False)¶
- get_joining_fields(reverse_join=False)¶
- get_limit_choices_to()¶
Return
limit_choices_to
for this model field.If it is a callable, it will be invoked and the result will be returned.
- get_lookup(lookup_name)¶
- get_path_info(filtered_relation=None)¶
Get path from this field to the related model.
- get_pk_value_on_save(instance)¶
Hook to generate new PK values on save. This method is called when saving instances with no primary key value set. If this method returns something else than None, then the returned value is used when saving the new instance.
- get_prep_value(value)¶
- get_reverse_joining_columns()¶
- get_reverse_joining_fields()¶
- get_reverse_path_info(filtered_relation=None)¶
Get path from the related model to this field’s model.
Complement to get_forward_related_filter(). Return the keyword arguments that when passed to self.related_field.model.object.filter() select all instances of self.related_field.model related through this field to obj. obj is an instance of self.model.
- get_transform(lookup_name)¶
- has_default()¶
Return a boolean of whether this field has a default value.
- is_cached(instance)¶
- pre_save(model_instance, add)¶
Return field’s value just before saving.
- register_instance_lookup(lookup, lookup_name=None)¶
- rel_db_type(connection)¶
Return the data type that a related field pointing to this field should use. For example, this method is called by ForeignKey and OneToOneField to determine its data type.
Define the name that can be used to identify this related object in a table-spanning query.
- run_validators(value)¶
- save_form_data(instance, data)¶
- select_format(compiler, sql, params)¶
Custom format for select clauses. For example, GIS columns need to be selected as AsText(table.col) on MySQL as the table.col data can’t be used by Django.
- set_attributes_from_name(name)¶
- set_attributes_from_rel()¶
- set_cached_value(instance, value)¶
- slice_expression(expression, start, length)¶
Return a slice of this field.
- to_python(value)¶
- validate(value, model_instance)¶
- value_from_object(obj)¶
Return the value of this field in the given model instance.
- value_to_string(obj)¶
Return a string value of this field from the passed obj. This is used by the serialization framework.