I have a multiple product models:
class ProductModelA(..
class ProductModelB(..
class ProductModelC(..
Model Order
and SubOrder
which stores information about quantity. So every Order
can have multiple SubOrders
which stores tuple product
and quantity
.
class Order(..
class SubOrder(models.Model):
order = models.ForeignKey('orders.Order',on_delete=models.CASCADE,related_name='suborders')
product = GenericForeignKey()
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, related_name='suborders')
object_id = models.PositiveIntegerField()
amount = models.PositiveIntegerField(..)
I'm trying to make user friendly admin interface with inline suborder
. Choosing from existing product
s would be enough (alongside with amount field) but can't figure out how to do that.
I tried:
class SubOrderInline(GenericTabularInline):
model = SubOrder
@admin.register(Order)
class OAdmin(admin.ModelAdmin):
inlines = [SubOrderInline]
But it doesn't work:
I don't want to choose from Order
objects, I want to choose from either ProductModelA
,ProductModelB
or ProductModelC
objects. Is there a built in way?