Make sure that a list of valid fields is being used.
(self, value)
| 934 | return super().__get__(instance, owner) |
| 935 | |
| 936 | def validate(self, value): |
| 937 | """Make sure that a list of valid fields is being used.""" |
| 938 | if not isinstance(value, (list, tuple, BaseQuerySet)): |
| 939 | self.error("Only lists and tuples may be used in a list field") |
| 940 | |
| 941 | # Validate that max_length is not exceeded. |
| 942 | # NOTE It's still possible to bypass this enforcement by using $push. |
| 943 | # However, if the document is reloaded after $push and then re-saved, |
| 944 | # the validation error will be raised. |
| 945 | if self.max_length is not None and len(value) > self.max_length: |
| 946 | self.error("List is too long") |
| 947 | |
| 948 | super().validate(value) |
| 949 | |
| 950 | def prepare_query_value(self, op, value): |
| 951 | # Validate that the `set` operator doesn't contain more items than `max_length`. |