Skip to content

prevent embedded models from being created in a separate collection #216

@timgraham

Description

@timgraham

Models that are embedded generally shouldn't have their own collection. They can't be abstract because abstract models can't be instantiated and our syntax for creating objects with embedded models is:

Book.objects.create(
    author=Author(name="Shakespeare", age=55, address=Address(city="NYC", state="NY"))
)

Proposal:

  • Create an EmbeddedModel class that overrides save() to raise NotSupportedError.
  • The SchemaEditor will ignore EmbeddedModel subclasses.
  • EmbeddedModel will use a custom manager that raises NotSupportedError for all QuerySet write operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions