Friday, October 29, 2010

Re: Model Inheritance.

Hi Tom,

You might want to have a look at inheritanceCastModel from django-model-utils by Carl Meyer 
Best regards,
Miguel Araujo

2010/10/29 David De La Harpe Golden <david.delaharpe.golden@ichec.ie>
On 29/10/10 00:04, Tom Eastman wrote:

That's correct, but I want to take a 'Place' object, that doesn't have a
'restaurant', and turn it *in to* a 'Restaurant' by adding the
corresponding row to the Restaurant table.


So you have a place.

p = Place(name="3rd Circle of Hell")
p.save()

This should work:

r = Restaurant(serves_hot_dogs=True)
r.place_ptr = p
r.save()

If you then want an r that has picked up the now-should-be-inherited place attrs, you'll have to do something like:

r = Restaurant.objects.get(pk=r.pk)

print r.name
3rd Circle of Hell



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


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

No comments:

Post a Comment