0

如何显示OrderAdminBasket所有者、产品、产品数量?

我尝试内联:

管理员.py:

class BasketInline(admin.TabularInline):
    model = Basket

class OrderAdmin(admin.ModelAdmin):
    inlines = [
        BasketInline,
    ]
admin.site.register(Order, OrderAdmin)

但它不起作用。

class Basket(models.Model):
    owner = models.ForeignKey(User, related_name='user_basket', verbose_name='Owner')
    name = models.CharField("Basket_Name", max_length=30)
    products = models.ManyToManyField('Product', through='BasketProduct', blank=True, null=True)


class BasketProduct(models.Model):
    product = models.ForeignKey('Product')
    basket = models.ForeignKey('Basket')
    quantity = models.IntegerField()

class Product(models.Model):
    name = models.CharField(max_length=50)
    slug = models.SlugField()
    unit_price = models.DecimalField(max_digits=5, decimal_places=2)
    desc = models.TextField()
    category = models.ManyToManyField(Category)

class ShippingOptions(models.Model):
    name = models.CharField(max_length=50)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    time = models.CharField(max_length=150)

class Order(models.Model):
    bask = models.OneToOneField(Basket)
    shipp = models.OneToOneField(ShippingOptions)

也许我需要一种不同的方式。请任何帮助。谢谢

4

1 回答 1

0

Order您需要在模型中打开 foreignKey Basket

class Basket(models.Model):
    owner = models.ForeignKey(User, related_name='user_basket', verbose_name='Owner')
    name = models.CharField("Basket_Name", max_length=30)
    products = models.ManyToManyField('Product', through='BasketProduct', blank=True, null=True)
    owner = models.ForeignKey(Owner, blank=True, verbose_name='Owner')

或者您在第一个模型行中有错误:

owner = models.ForeignKey(Owner, related_name='user_basket', verbose_name='Owner')
于 2012-10-03T11:38:18.683 回答