我正在把一个Satchmo应用程序的管理员放在一起.Satchmo使用ONETOONE关系来扩展基础Product
模型,我想在一个页面上对其进行编辑.
是否可以将一对一关系作为内联关系?如果不是,向我管理的给定页面添加几个字段的最佳方式是什么,这些字段最终将保存到ONETOONE关系中?
例如:
class Product(models.Model):
name = models.CharField(max_length=100)
...
class MyProduct(models.Model):
product = models.OneToOne(Product)
...
我为我的管理员try 了这个,但它不起作用,似乎需要外键:
class ProductInline(admin.StackedInline):
model = Product
fields = ('name',)
class MyProductAdmin(admin.ModelAdmin):
inlines = (AlbumProductInline,)
admin.site.register(MyProduct, MyProductAdmin)
这将抛出此错误:<class 'satchmo.product.models.Product'> has no ForeignKey to <class 'my_app.models.MyProduct'>
要做到这一点,唯一的办法是Custom Form吗?
edit:刚刚try 了以下代码直接添加字段...也不起作用:
class AlbumAdmin(admin.ModelAdmin):
fields = ('product__name',)