Thank you for this link. The InheritanceManager is good to know about. But 
it does not help creating the child_instance from a base instance. At least 
the docs don't tell about it. Or I was blind.

Am Mittwoch, 13. Mai 2015 05:41:44 UTC+2 schrieb somecallitblues:
>
> Have you had a look at 
> http://django-model-utils.readthedocs.org/en/latest/managers.html#inheritancemanager?
>  
> I'm not sure if it will help but it's kind of related to what you've posted.
>
> On 12 May 2015 at 23:10, guettli <h...@tbz-pariv.de <javascript:>> wrote:
>
>> Hi,
>>
>> this ticket is seven years old
>>
>> https://code.djangoproject.com/ticket/7623
>>
>> {{{
>>
>> As it exists now, multi-table inheritance does not allow for the creation 
>> of a child model instance that inherits from an existing parent model 
>> instance. For example:
>>  
>> Parent Class-
>>  
>> class Place(models.Model):
>>     name = models.CharField(max_length=50)
>>     address = models.TextField(max_length=150)
>>
>> Child Classes-
>>  
>> class Restaurant(Place):
>>     place = models.OneToOneField(Place, parent_link=True)
>>     cuisine = models.CharField(max_length=75)
>>     rating = models.IntegerField()
>>
>> class Bar(Place):
>>     parent = models.OneToOneField(Place, parent_link=True)
>>     happy_hour = models.BooleanField()
>>     beers_on_tap = models.ManyToManyField("Beers", null=True, blank=True)
>>
>> Sample Use-case-
>>  
>> When the system is first deployed, a restaurant instance is created. 
>> Later, the restaurant adds a bar to increase revenue, and we now want to 
>> create a Bar model instance for the parent Place for the restaurant. I 
>> would propose the following interface for doing so:
>>  
>> parentPlace = Restaurant.objects.get(name__iexact="Bob's Place").parent
>> barInstance = Bar(parent=parentPlace, happy_hour=True)
>>
>> However, if you attempt to create an instance in this manner now, you 
>> receive a DatabaseIntegrityError, saying that a Place object with that id 
>> already exists.
>>
>> }}}
>>
>> How to get this solved?
>>
>> There are work arounds:
>>
>>
>> http://stackoverflow.com/questions/4064808/django-model-inheritance-create-sub-instance-of-existing-instance-downcast
>>
>> {{{
>> extended_user = ExtendedUser(user_ptr_id=auth_user.pk)
>> extended_user.__dict__.update(auth_user.__dict__)
>> extended_user.save()
>> }}}
>>
>> Or is there a better solution in current django versions?
>>
>>
>>
>>
>>
>>
>>  
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d4273754-670e-4697-b0b4-9626c42a5aaf%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/d4273754-670e-4697-b0b4-9626c42a5aaf%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/274e9ef0-afb5-4b73-80ce-19440a78ecfb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to