class ManyToManyField(RelatedField):
Provide a many-to-many relation by using an intermediary model that holds two ForeignKey fields pointed at the two sides of the relation.
Unless a through model was provided, ManyToManyField will use the create_many_to_many_intermediary_model factory to automatically generate the intermediary model.
Method | __init__ |
Undocumented |
Method | _check_ignored_options |
Undocumented |
Method | _check_relationship_model |
Undocumented |
Method | _check_table_uniqueness |
Undocumented |
Method | _check_unique |
Undocumented |
Method | _get_m2m_attr |
Function that can be curried to provide the source accessor or DB column name for the m2m table. |
Method | _get_m2m_db_table |
Function that can be curried to provide the m2m table name for this relation. |
Method | _get_m2m_reverse_attr |
Function that can be curried to provide the related accessor or DB column name for the m2m table. |
Method | _get_path_info |
Called by both direct and indirect m2m traversal. |
Method | check |
Undocumented |
Method | contribute_to_class |
Register the field with the model class it belongs to. |
Method | contribute_to_related_class |
Undocumented |
Method | db_check |
Return the database column check constraint for this field, for the provided connection. Works the same way as db_type() for the case that get_internal_type() does not map to a preexisting model field. |
Method | db_parameters |
Extension of db_type(), providing a range of different return values (type, checks). This will look at db_type(), allowing custom model fields to override it. |
Method | db_type |
Return the database column data type for this field, for the provided connection. |
Method | deconstruct |
Return enough information to recreate the field as a 4-tuple: |
Method | formfield |
Pass limit_choices_to to the field being constructed. |
Method | get_path_info |
Undocumented |
Method | get_reverse_path_info |
Undocumented |
Method | save_form_data |
Undocumented |
Method | set_attributes_from_rel |
Undocumented |
Method | value_from_object |
Return the value of this field in the given model instance. |
Class Variable | description |
Undocumented |
Class Variable | many_to_many |
Undocumented |
Class Variable | many_to_one |
Undocumented |
Class Variable | one_to_many |
Undocumented |
Class Variable | one_to_one |
Undocumented |
Instance Variable | db_table |
Undocumented |
Instance Variable | has_null_arg |
Undocumented |
Instance Variable | m2m_column_name |
Undocumented |
Instance Variable | m2m_db_table |
Undocumented |
Instance Variable | m2m_field_name |
Undocumented |
Instance Variable | m2m_reverse_field_name |
Undocumented |
Instance Variable | m2m_reverse_name |
Undocumented |
Instance Variable | m2m_reverse_target_field_name |
Undocumented |
Instance Variable | m2m_target_field_name |
Undocumented |
Instance Variable | swappable |
Undocumented |
Inherited from RelatedField
:
Method | _check_clashes |
Check accessor and reverse query name clashes. |
Method | _check_referencing_to_swapped_model |
Undocumented |
Method | _check_related_name_is_valid |
Undocumented |
Method | _check_related_query_name_is_valid |
Undocumented |
Method | _check_relation_model_exists |
Undocumented |
Method | do_related_class |
Undocumented |
Method | get_cache_name |
Undocumented |
Method | get_forward_related_filter |
No summary |
Method | get_limit_choices_to |
Return limit_choices_to for this model field. |
Method | get_reverse_related_filter |
No summary |
Method | related_query_name |
Define the name that can be used to identify this related object in a table-spanning query. |
Instance Variable | _limit_choices_to |
Undocumented |
Instance Variable | _related_name |
Undocumented |
Instance Variable | _related_query_name |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | opts |
Undocumented |
Instance Variable | verbose_name |
Undocumented |
Property | related_model |
Undocumented |
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. |
Property | target_field |
When filtering against this relation, return the field on the remote model against which the filtering should happen. |
Inherited from FieldCacheMixin
(via RelatedField
):
Method | delete_cached_value |
Undocumented |
Method | get_cached_value |
Undocumented |
Method | is_cached |
Undocumented |
Method | set_cached_value |
Undocumented |
Inherited from Field
(via RelatedField
):
Class Method | _choices_is_value |
Undocumented |
Method | __copy__ |
Undocumented |
Method | __deepcopy__ |
Undocumented |
Method | __eq__ |
Undocumented |
Method | __hash__ |
Undocumented |
Method | __lt__ |
Undocumented |
Method | __reduce__ |
Pickling should return the model._meta.fields instance of the field, not a new copy of that field. So, use the app registry to load the model and then the field back. |
Method | __repr__ |
Display the module, class, and name of the field. |
Method | __str__ |
Return "app_label.model_label.field_name" for fields attached to models. |
Method | _check_backend_specific_checks |
Undocumented |
Method | _check_choices |
Undocumented |
Method | _check_db_index |
Undocumented |
Method | _check_deprecation_details |
Undocumented |
Method | _check_field_name |
Check if field name is valid, i.e. 1) does not end with an underscore, 2) does not contain "__" and 3) is not "pk". |
Method | _check_null_allowed_for_primary_keys |
Undocumented |
Method | _check_validators |
Undocumented |
Method | _description |
Undocumented |
Method | _get_flatchoices |
Flattened version of choices tuple. |
Method | cast_db_type |
Return the data type to use in the Cast() function. |
Method | clean |
Convert the value's type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised. |
Method | clone |
Uses deconstruct() to clone a new copy of this Field. Will not preserve any class attachments/attribute names. |
Method | db_type_parameters |
Undocumented |
Method | db_type_suffix |
Undocumented |
Method | get_attname |
Undocumented |
Method | get_attname_column |
Undocumented |
Method | get_choices |
Return choices with a default blank choices included, for use as <select> choices for this field. |
Method | get_col |
Undocumented |
Method | get_db_converters |
Undocumented |
Method | get_db_prep_save |
Return field's value prepared for saving into a database. |
Method | get_db_prep_value |
Return field's value prepared for interacting with the database backend. |
Method | get_default |
Return the default value for this field. |
Method | get_filter_kwargs_for_object |
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. |
Method | get_internal_type |
Undocumented |
Method | get_pk_value_on_save |
No summary |
Method | get_prep_value |
Perform preliminary non-db specific value checks and conversions. |
Method | has_default |
Return a boolean of whether this field has a default value. |
Method | pre_save |
Return field's value just before saving. |
Method | rel_db_type |
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. |
Method | run_validators |
Undocumented |
Method | select_format |
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. |
Method | set_attributes_from_name |
Undocumented |
Method | to_python |
Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can't be converted. Return the converted value. Subclasses should override this. |
Method | validate |
Validate value and raise ValidationError if necessary. Subclasses should override this to provide validation logic. |
Method | value_to_string |
Return a string value of this field from the passed obj. This is used by the serialization framework. |
Class Variable | auto_creation_counter |
Undocumented |
Class Variable | default_error_messages |
Undocumented |
Class Variable | default_validators |
Undocumented |
Class Variable | empty_strings_allowed |
Undocumented |
Class Variable | empty_values |
Undocumented |
Class Variable | flatchoices |
Undocumented |
Class Variable | hidden |
Undocumented |
Class Variable | system_check_deprecated_details |
Undocumented |
Class Variable | system_check_removed_details |
Undocumented |
Instance Variable | _db_tablespace |
Undocumented |
Instance Variable | _error_messages |
Undocumented |
Instance Variable | _unique |
Undocumented |
Instance Variable | _validators |
Undocumented |
Instance Variable | _verbose_name |
Undocumented |
Instance Variable | attname |
Undocumented |
Instance Variable | auto_created |
Undocumented |
Instance Variable | blank |
Undocumented |
Instance Variable | choices |
Undocumented |
Instance Variable | column |
Undocumented |
Instance Variable | concrete |
Undocumented |
Instance Variable | creation_counter |
Undocumented |
Instance Variable | db_column |
Undocumented |
Instance Variable | db_index |
Undocumented |
Instance Variable | default |
Undocumented |
Instance Variable | editable |
Undocumented |
Instance Variable | error_messages |
Undocumented |
Instance Variable | help_text |
Undocumented |
Instance Variable | is_relation |
Undocumented |
Instance Variable | max_length |
Undocumented |
Instance Variable | model |
Undocumented |
Instance Variable | null |
Undocumented |
Instance Variable | primary_key |
Undocumented |
Instance Variable | remote_field |
Undocumented |
Instance Variable | serialize |
Undocumented |
Instance Variable | unique_for_date |
Undocumented |
Instance Variable | unique_for_month |
Undocumented |
Instance Variable | unique_for_year |
Undocumented |
Property | _get_default |
Undocumented |
Property | cached_col |
Undocumented |
Property | db_returning |
Private API intended only to be used by Django itself. Currently only the PostgreSQL backend supports returning multiple fields on a model. |
Property | db_tablespace |
Undocumented |
Property | unique |
Undocumented |
Property | validators |
Some validators can't be created at field initialization time. This method provides a way to delay their creation until required. |
Inherited from RegisterLookupMixin
(via RelatedField
, Field
):
Class Method | get_lookups |
Undocumented |
Class Method | register_lookup |
Undocumented |
Static Method | merge_dicts |
Merge dicts in reverse to preference the order of the original list. e.g., merge_dicts([a, b]) will preference the keys in 'a' over those in 'b'. |
Class Method | _clear_cached_lookups |
Undocumented |
Class Method | _get_lookup |
Undocumented |
Class Method | _unregister_lookup |
Remove given lookup from cls lookups. For use in tests only as it's not thread-safe. |
Method | get_lookup |
Undocumented |
Method | get_transform |
Undocumented |
Undocumented
Register the field with the model class it belongs to.
If private_only is True, create a separate instance of this field for every subclass of cls, even if cls is not an abstract model.
django.db.models.fields.Field.db_check
Return enough information to recreate the field as a 4-tuple:
- The name of the field on the model, if contribute_to_class() has been run.
- The import path of the field, including the class, e.g. django.db.models.IntegerField. This should be the most portable version, so less specific may be better.
- A list of positional arguments.
- A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
- None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
- UUID
- datetime.datetime (naive), datetime.date
- top-level classes, top-level functions - will be referenced by their full import path
- Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There's no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
Pass limit_choices_to to the field being constructed.
Only passes it if there is a type that supports related fields. This is a similar strategy used to pass the queryset to the field being constructed.