Sunday, August 16, 2015

Re: Django: "Fake" multiple inheritance

Thank you Daniel,

I found another way.

Best,
Michael

On 14 August 2015 at 23:17, Daniel H <dh.harris183@gmail.com> wrote:
Hi Michael.

First of all, setting the pk to the pk of a different model will do nothing.

You can do this however, using Foreign Keys

restaurant = models.ForeignKey('Restautant')

Then declare a new hotel object like this:

restaurant = Restaurant.objects.get(name='Will soon be a hotel')
Hotel.objects.create(restaurant=restaurant.pk)

What does the "Place" table represent?


On Friday, August 14, 2015 at 7:35:26 AM UTC-7, mic...@herrmann.io wrote:
Hi all,

suppose I have the following model structure

    from django.db import models
    
    class Place(models.Model):
        name = models.CharField(max_length=50)
    
    class Restaurant(Place):
        ...
    
    class Hotel(Place):
        ...

I already have a Restaurant in my database. This Restaurant is now also becoming a Hotel. I would like to declare this in the database as follows:

    restaurant = Restaurant.objects.get(name='Will soon be a hotel')
    Hotel.objects.create(pk=restaurant.pk)

Is this a safe thing to do?

Thanks,
Michael

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/26Qu9-wJ1gA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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/c270d98c-7a14-4870-9f04-3ccfcb3abeb3%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


Michael Herrmann, MSc
Alser Straße 18/26
1090 Wien
Tel.: +43 699 11 65 16 40

--
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+unsubscribe@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/CABrKpmBK%3DY7oqufPj7OhmAT7WJ2i9t8XevuftO8-OS46BHWyjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment