-
-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Create from super #65
base: master
Are you sure you want to change the base?
Conversation
… However, this commit resolves the id problems that appear when testing on mysql in the simplest way possible. Tested on sqlite and mysql, but not postgres
…from an instance of it's superclass. Useful if you don't know what class it should be when initially created.
This is a feature we'd surely can use. However, I'm not happy about the API yet, I'd prefer using something like In one of my projects I've also "upgraded" an object to it's subclass, using:
See https://code.djangoproject.com/ticket/7623 :) Do you see a way to incorporate these idea's? |
Yes, I agree about the API. I suppose it should live in Thanks for pointing me to the ticket about this feature. I hadn't noticed Joshua On Wed, Jan 8, 2014 at 1:26 AM, Diederik van der Boor <
|
I changed it to live in PolymorphicQuerySet for API consistency and updated If ModelB inherits from ModelA the call would look like: modelb_instance = ModelB.objects.create_from_super(modela_instance, I read through ticket 7623. Is someone else already working on this? It Also, do you have an opinion on the method name? Joshua On Wed, Jan 8, 2014 at 1:26 AM, Diederik van der Boor <
|
Hi Diederik, Checking in on this... I changed the API as you suggested, but I'm not sure I see there is some recent activity on ticket 7623. Should I post my Thanks, On Wed, Jan 8, 2014 at 1:26 AM, Diederik van der Boor <
|
Whoops! I haven't taken the time for it, and didn't notice some GitHub notifications. |
This is in interesting feature, but it seems only useful for the use case where you want to downcast after creation. What about the common use case where you need to recast a derived class? Currently this doesn't seem to be possible. Is there any chance to extend this to support this? Perhaps with a |
Actually there isn't really a problem with that. They're just entries in a Consider: class ModelA(PolymorphicModel):
Most use cases will probably want to delete the old class data immediately, Joshua On Thu, Apr 3, 2014 at 8:51 PM, Andrew Cutler [email protected]:
|
@JCoxwell thank you for the concise example. I was lead astray by the following exception:
Note the omission of In any case I think this usage could be better documented, or perhaps more obvious. |
I honestly hadn't considered the recasting use case until you brought it The exception means that it will only work to cast one level down from an Joshua On Mon, Apr 14, 2014 at 2:28 AM, Andrew Cutler [email protected]:
|
I'm not sure if you want this feature, but I thought I'd offer it. Basically it allows you to convert a polymorphic model to a new class down the hierarchy (one level). For example, if ModelB subclasses ModelA then an instance of ModelA can become an instance of ModelB by adding the additional fields without changing it's primary key.
I use this feature to create objects that need to be classified later.
There are 2 commits which can be applied separately:
One is the feature itself with a test.
The other modifies the tests to work with MySQL. Apparently sqlite reuses ids where as MySQL does not, so I just push the ids into the repr strings for comparison. This is the simplest solution I could think of, but it's not ideal. At least they pass...