multi-table-inheritance

Django post_save signal on parent class with multi-table inheritance

隐身守侯 提交于 2020-01-01 10:46:13
问题 In Django, if you have models that use multi-table inheritance, and you define a receiver for a post_save signal on the parent class, does that receiver function get called when an instance of the child class is saved? Borrowing an example from another question: class Animal(models.Model): category = models.CharField(max_length=20) class Dog(Animal): color = models.CharField(max_length=10) def echo_category(sender, **kwargs): print "category: '%s'" % kwargs['instance'].category post_save

how to conditionally save a form using django multi table inheritance

时光毁灭记忆、已成空白 提交于 2019-12-12 01:54:18
问题 I have the following form: class PlaceForm(forms.ModelForm): class Meta: model = Place I have the following models: class Place(models.Model): customer = models.ForeignKey(Customer) name = models.CharField(max_length=50) address = models.CharField(max_length=80) class Restaurant(Place): serves_hot_dogs = models.BooleanField() serves_pizza = models.BooleanField() In my view I want to conditionally save either a Place or a Restaurant depending on the incoming url. I have tried the following: if

Django post_save signal on parent class with multi-table inheritance

别来无恙 提交于 2019-12-04 08:41:18
In Django, if you have models that use multi-table inheritance, and you define a receiver for a post_save signal on the parent class, does that receiver function get called when an instance of the child class is saved? Borrowing an example from another question : class Animal(models.Model): category = models.CharField(max_length=20) class Dog(Animal): color = models.CharField(max_length=10) def echo_category(sender, **kwargs): print "category: '%s'" % kwargs['instance'].category post_save.connect(echo_category, sender=Animal) If I do: >>> dog = Dog.objects.get(...) >>> dog.category = "canine"

Should I avoid multi-table (concrete) inheritance in Django by any means?

烂漫一生 提交于 2019-11-26 21:54:18
Many experienced developers recommend against using Django multi-table inheritance because of its poor performance: Django gotcha: concrete inheritance by Jacob Kaplan-Moss , a core contributor of Django. In nearly every case, abstract inheritance is a better approach for the long term. I’ve seen more than few sites crushed under the load introduced by concrete inheritance, so I’d strongly suggest that Django users approach any use of concrete inheritance with a large dose of skepticism. Two Scoops of Django by Daniel Greenfield ( @pydanny ) Multi-table inheritance, sometimes called “concrete

Should I avoid multi-table (concrete) inheritance in Django by any means?

怎甘沉沦 提交于 2019-11-26 06:30:22
问题 Many experienced developers recommend against using Django multi-table inheritance because of its poor performance: Django gotcha: concrete inheritance by Jacob Kaplan-Moss, a core contributor of Django. In nearly every case, abstract inheritance is a better approach for the long term. I’ve seen more than few sites crushed under the load introduced by concrete inheritance, so I’d strongly suggest that Django users approach any use of concrete inheritance with a large dose of skepticism. Two