> Given the following:
> 
> class Place(models.Model):
>     name = models.CharField(max_length=50)
>     address = models.CharField(max_length=80)
>     zip_code = models.CharField(max_length=15)
> 
> 
> class Restaurant(Place):
>     serves_hot_dogs = models.BooleanField()
>     serves_pizza = models.BooleanField()
> 
> class GardenStore(Place):
>     sells_lady_bugs = models.BooleanField()
> 
> 
> and given a query on zip_code in Places, how would I know whether a
> Place is a Restaurant or a Garden Store?

You don't OOTB.

I asked same thing quite a while ago - you should be able to find my thoughts 
somewhere in this group archives.

Rationale behind this is that you're trying to achieve something pretty much 
impossible - inheritance in relational world. 

Thing is that you can have you can really have both: Restaurant and 
GardenStore instance to point to same place - so is that correct case or not?

Note that "inheritance" is made so that you have relation from Restaurant and 
GardenStore tables to Place. There is no simple mechanism to prevent your data 
to have references from both "children" to point to "parent".

You can have property/method on your model that tries to determine which one 
is correct.

Or you can re-factor your models (which is usually less painful) so that your 
place, provided that it is unique (which actually in this case might not be). 
Add simple discriminator field to tell what type of child you must also fetch 
to make data complete.

-- 

Jani Tiainen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to