murgatroid99
murgatroid99

Reputation: 20297

Django workflow to convert model superclass to subclass

I have a Django project with two models: Applicant and Client, where Client is a subclass of Applicant. I would like some way of allowing a user to add an existing Applicant instance as a Client. I already have a view for Applicant instances, so I thought that having a Client model form on that page would do this, but from the documentation it does not look like you can initialize a model form with an instance of a superclass. I know I could do this by having code that goes directly to the database and adds a field to the subclass table, but is there a more Django-y way of doing it?

Upvotes: 3

Views: 1087

Answers (1)

dgel
dgel

Reputation: 16806

You can create a Client instance from an existing Applicant instance with the following code:

client = Client(applicant_ptr=applicant)
client.save_base(raw=True)

Upvotes: 10

Related Questions