Skip to content

Commit

Permalink
edit error message
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Jan 13, 2025
1 parent 961e358 commit fae14f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions django_mongodb_backend/fields/embedded_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def check(self, **kwargs):
if field.remote_field:
errors.append(
checks.Error(
"Embedded models cannot have relational fields.",
"Embedded models cannot have relational fields "
f"({self.embedded_model().__class__.__name__}.{field.name} "
f"is a {field.__class__.__name__}).",
obj=self,
id="django_mongodb.embedded_model.E001",
)
Expand All @@ -46,9 +48,7 @@ def get_internal_type(self):
def _set_model(self, model):
"""
Resolve embedded model class once the field knows the model it belongs
to.
If __init__()'s embedded_model argument is a string, resolve it to the
to. If __init__()'s embedded_model argument is a string, resolve it to the
corresponding model class, similar to relation fields.
"""
self._model = model
Expand Down
2 changes: 1 addition & 1 deletion django_mongodb_backend/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _create_model_indexes(self, model, column_prefix="", parent_model=None):
Create all indexes (field indexes & uniques, Meta.index_together,
Meta.unique_together, Meta.constraints, Meta.indexes) for the model.
If this is a recursive call to due to an embedded model, `column_prefix`
If this is a recursive call due to an embedded model, `column_prefix`
tracks the path that must be prepended to the index's column, and
`parent_model` tracks the collection to add the index/constraint to.
"""
Expand Down
4 changes: 3 additions & 1 deletion tests/model_fields_/test_embedded_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,6 @@ class MyModel(models.Model):
# The inner CharField has a non-positive max_length.
self.assertEqual(errors[0].id, "django_mongodb.embedded_model.E001")
msg = errors[0].msg
self.assertEqual(msg, "Embedded models cannot have relational fields.")
self.assertEqual(
msg, "Embedded models cannot have relational fields (Target.key is a ForeignKey)."
)

0 comments on commit fae14f2

Please sign in to comment.