Django Admin: OneToOne Relation as an Inline?
        Posted  
        
            by Jim Robert
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jim Robert
        
        
        
        Published on 2009-11-16T19:10:26Z
        Indexed on 
            2010/03/14
            0:35 UTC
        
        
        Read the original article
        Hit count: 650
        
I am putting together the admin for a satchmo application. Satchmo uses OneToOne relations to extend the base Product model, and I'd like to edit it all on one page.
It is possible to have a OneToOne relation as an Inline? If not, what is the best way to add a few fields to a given page of my admin that will eventually be saved into the OneToOne relation?
for example:
class Product(models.Model):
    name = models.CharField(max_length=100)
    ...
class MyProduct(models.Model):
    product = models.OneToOne(Product)
    ...
I tried this for my admin but it does not work, and seems to expect a Foreign Key:
class ProductInline(admin.StackedInline):
    model = Product
    fields = ('name',)
class MyProductAdmin(admin.ModelAdmin):
    inlines = (AlbumProductInline,)
admin.site.register(MyProduct, MyProductAdmin)
Which throws this error: <class 'satchmo.product.models.Product'> has no ForeignKey to <class 'my_app.models.MyProduct'>
Is the only way to do this a Custom Form?
edit: Just tried the following code to add the fields directly... also does not work:
class AlbumAdmin(admin.ModelAdmin):
    fields = ('product__name',)
© Stack Overflow or respective owner