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 
<https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey>

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, [email protected] 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 the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
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.

Reply via email to