-
-
Notifications
You must be signed in to change notification settings - Fork 302
Open
Description
class Order(models.Model):
title = models.CharField(_("Title"), max_length=200)
class Meta:
ordering = ('title',)
def __str__(self):
return self.title
class Payment(PolymorphicModel):
order = models.ForeignKey(Order, on_delete=models.CASCADE)
amount = models.DecimalField(default=0, blank=True, max_digits=10, decimal_places=2)
index = models.PositiveIntegerField(default=0, blank=False)
class Meta:
ordering = ('index',)
class CreditCardPayment(Payment):
card_type = models.CharField()
class Beneficiary(models.Model):
firstname = models.CharField()
lastname = models.CharField()
class SepaPayment(Payment):
iban = models.CharField()
bic = models.CharField()
beneficiaries = models.ManyToManyField(Beneficiary, "sepa", blank=True)When deleting an Order whose first Payment is of type SepaPayment, an exception is raised :
Exception Value: Cannot query <CreditCardPayment>: Must be "SepaPayment" instance.
This is because of this code in django core: https://github.com/django/django/blob/master/django/db/models/deletion.py#L193
The model type is taken from the first element in the polymorphic collection
Minimal example here: https://github.com/unusual-thoughts/django-poly-bug
tuxella, milano-slesarik, OskarPersson, qwaqwa93TW, avallintine and 1 more
Metadata
Metadata
Assignees
Labels
No labels