简体   繁体   English

Google App Engine上Django admin中内联用户配置文件的奇怪行为

[英]Odd behavior with inlined user profile in Django admin on Google App Engine

We're using a subclass of UserAdmin to add our user profile in Django 1.4 app on Google App Engine 1.8.1. 我们使用UserAdmin的子类在Google App Engine 1.8.1的Django 1.4应用程序中添加用户配置文件。 Until recently, this worked fine, but the user profile won't show up in our app's admin interface when served from App Engine (ie appspot.com). 直到最近,这种方法都可以正常工作,但是从App Engine(即appspot.com)提供服务时,用户个人资料不会显示在我们应用程序的管理界面中。 Oddly, however, it still works just fine running on my development machine within the SDK and running under AppEngine Launcher. 不过,奇怪的是,它仍然可以在我的SDK上的开发计算机上运行,​​并在AppEngine Launcher下运行。

Anyone else have any experience with this issue and possibly have a solution? 其他人对此问题有任何经验并可能有解决方案吗?

Here's the code we're using (in admin.py for our app): 这是我们正在使用的代码(在应用程序的admin.py中):

admin.site.unregister(User)


class UserProfileInline(admin.StackedInline):
    model = UserProfile


class UserModelAdmin(UserAdmin):
    inlines = [UserProfileInline, ]
    list_display = ('username', )
    search_fields = ['username']


admin.site.register(User, UserModelAdmin)

It's nearly identical to code in a related SO question ; 它与相关的SO问题中的代码几乎相同; the odd thing is it works in my dev environment but NOT on the server. 奇怪的是,它可以在我的开发环境中工作,但不能在服务器上工作。 Any ideas? 有任何想法吗?

Turns out the problem was related to a ForeignKey field ( school ) that had approx 100,000 options to choose from. 原来问题出在与ForeignKey字段( school )有关,该字段有大约100,000个选项可供选择。 The query to get all those names to build a drop-down list was timing out on App Engine. 获取所有这些名称以构建下拉列表的查询在App Engine上超时。 The solution was to make that particular related field read only: 解决方案是使该特定相关字段为只读:

class UserProfileInline(admin.StackedInline):
    model = UserProfile
    readonly_fields = ('school', 'file_data')

This didn't really affect our app. 这并没有真正影响我们的应用程序。 The admin is purposefully limited because users should make changes themselves for the most part using forms on the front end; 管理员受到有意限制的原因是,用户应在很大程度上使用前端的表单自行进行更改; the school field uses an AJAX call to query the database to do a sort of auto-fill, returning matches as a user types in the text field. school字段使用AJAX调用来查询数据库以进行某种自动填充,并在用户在文本字段中键入内容时返回匹配项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM