开发者

Inlines in Django Admin

开发者 https://www.devze.com 2022-12-31 16:23 出处:网络
I have two models, Order and UserProfile. Each Order has a ForeignKey to UserProfile, to associate it with that user.

I have two models, Order and UserProfile. Each Order has a ForeignKey to UserProfile, to associate it with that user.

On the django admin page for each Order, I'd like to display the UserProfile associated with it, for easy processing of information.

I have tried inlines:

class UserInline(admin.TabularInline):
    model = UserProfile

class ValuationRequestAdmin(admin.ModelAdmin):
    list_display = ('address1', 'address2', 'town', 'date_added')
    list_filter = ('town', 'date_added')
    ordering = ('-date_updated',)   
开发者_如何学JAVA    inlines = [
        UserInline,
    ]

But it complains that UserProfile "has no ForeignKey to" Order - which it doesn't, it's the other way around.

Is there a way to do what I want?


How about making the UserProfile read only? Django Foreign Keys Read Only

There are other ideas in this post also.

0

精彩评论

暂无评论...
验证码 换一张
取 消