Skip to content

Recasting from base isn't pretty #45

@thejcannon

Description

@thejcannon

Let's say somehow I get an (unsaved) Animal instance. There isn't a pretty way to recast as a Canine or Feline:

animal = Animal('phoebo')

# This is a no-op thanks to https://github.com/craigds/django-typed-models/blob/master/typedmodels/models.py#L329
animal.recast(Feline)

# This doesn't work either (unless your model defines __str__ to be <app_name>.<model_name>)
animal.type = Feline

# These will work, but isn't ideal
animal.type = 'my_app.Feline'
animal.recast()

# This works too (but only by coincidence, by how recast is implemented)
animal.type = 'nonesense'
animal.recast(Feline)

IMO animal.recast(Feline) should be supported.
(setting the type is smelly, since type is supposed to be a string field)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions