Skip to content

Commit

Permalink
add support for ListField and EmbeddedModelField
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Oct 4, 2024
1 parent 5c29684 commit bec8461
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Checkout Django
uses: actions/checkout@v4
with:
repository: 'mongodb-forks/django'
repository: 'mongodb-forks/embedded-model-field'
ref: 'mongodb-5.0.x'
path: 'django_repo'
- name: Install system packages for Django's Python test dependencies
Expand Down
12 changes: 6 additions & 6 deletions django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,12 @@ def execute_sql(self, result_type):
elif hasattr(value, "prepare_database_save"):
if field.remote_field:
value = value.prepare_database_save(field)
else:
raise TypeError(
f"Tried to update field {field} with a model "
f"instance, {value!r}. Use a value compatible with "
f"{field.__class__.__name__}."
)
# else:
# raise TypeError(
# f"Tried to update field {field} with a model "
# f"instance, {value!r}. Use a value compatible with "
# f"{field.__class__.__name__}."
# )
prepared = field.get_db_prep_save(value, connection=self.connection)
if hasattr(value, "as_mql"):
prepared = prepared.as_mql(self, self.connection)
Expand Down
13 changes: 13 additions & 0 deletions django_mongodb/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ class DatabaseFeatures(BaseDatabaseFeatures):
# subclasses of BaseDatabaseIntrospection may require a get_constraints() method
"migrations.test_operations.OperationTests.test_add_func_unique_constraint",
"migrations.test_operations.OperationTests.test_remove_func_unique_constraint",
# Unsupported conversion from array to string in $convert with no onError value
"mongo_fields.test_listfield.IterableFieldsTests.test_options",
"mongo_fields.test_listfield.IterableFieldsTests.test_startswith",
# No results:
"mongo_fields.test_listfield.IterableFieldsTests.test_chained_filter",
"mongo_fields.test_listfield.IterableFieldsTests.test_equals",
"mongo_fields.test_listfield.IterableFieldsTests.test_exclude",
"mongo_fields.test_listfield.IterableFieldsTests.test_gt",
"mongo_fields.test_listfield.IterableFieldsTests.test_gte",
"mongo_fields.test_listfield.IterableFieldsTests.test_list_with_foreignkeys",
"mongo_fields.test_listfield.IterableFieldsTests.test_lt",
"mongo_fields.test_listfield.IterableFieldsTests.test_lte",
"mongo_fields.test_listfield.IterableFieldsTests.test_Q_objects",
}
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
_django_test_expected_failures_bitwise = {
Expand Down
3 changes: 2 additions & 1 deletion django_mongodb/fields/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .auto import ObjectIdAutoField
from .duration import register_duration_field
from .embedded_model import EmbeddedModelField, ListField
from .json import register_json_field

__all__ = ["register_fields", "ObjectIdAutoField"]
__all__ = ["register_fields", "EmbeddedModelField", "ListField", "ObjectIdAutoField"]


def register_fields():
Expand Down
Loading

0 comments on commit bec8461

Please sign in to comment.