I have some problems with Django ORM. I have three classes:
transaction.py
class Transaction(models.Model):
class Status(models.TextChoices):
PENDING = 'Pending'
PROCESSING = 'Processing'
CHARGED = 'Charged'
AUTHORIZED = 'Authorized'
CANCELLED = 'Cancelled'
REJECTED = 'Rejected'
ERROR = 'Error'
ISSUED = 'Issued'
amount = models.DecimalField(max_digits=6, decimal_places=2) # in USD
status = models.CharField(
max_length=15,
choices=Status.choices,
default=Status.PROCESSING,
)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
from_account = models.CharField(max_length=16)
to_account = models.CharField(max_length=16)
payments.py
class Payment(Transaction):
order = models.ForeignKey(Order, on_delete=models.CASCADE)
def __str__(self):
return f"Payment {super().__str__()}"
class Refund(Payment):
payment = models.ForeignKey(
Payment,
on_delete=models.CASCADE,
related_name='parent_payment'
)
def __str__(self):
return f"Refund payment={self.payment.id} {super(Transaction, self).__str__()}"
And when I trying to do migration I have this error
SystemCheckError: System check identified some issues:
ERRORS:
booking.Refund.payment: (models.E006) The field 'payment' clashes with the field 'payment' from model 'booking.transaction'.
As I understand the problem related to inheritance and its specific in ORM, but I'm not sure
CodePudding user response:
just add it
class Meta:
abstract = True