【问题标题】:extending satchmo user profile扩展 satchmo 用户配置文件
【发布时间】:2011-02-19 07:13:31
【问题描述】:

我正在尝试扩展 satchmo 商店中包含的基本用户注册表单和个人资料,但我遇到了问题。

这是我所做的:

创建一个新的应用程序“扩展配置文件”

编写了扩展 satchmo_store.contact.models 类并添加自定义名称字段的 models.py。

编写了一个 admin.py 来取消注册 Contact 类并注册我的新应用,但这仍然显示了默认的用户配置文件表单。

也许有人可以告诉我正确的方法吗?

【问题讨论】:

    标签: django django-models django-admin django-templates satchmo


    【解决方案1】:

    写了一个models.py来扩展 satchmo_store.contact.models 类和 添加自定义名称字段。

    写了一个 admin.py 来取消注册 联系班级并注册我的新应用 但这仍然向我显示默认值 用户个人资料表单。

    这与覆盖django注册User类有关; satchmo 项目为 User 类创建了一个外键(从 0.9.2 开始)。但是您要做的是创建一个带有新字段的扩展配置文件类。

    因此,在这种特定情况下,您需要做一些事情来覆盖显示联系信息的配置文件模板:

    1. 编写您自己的模型来继承 Contact 类(您已经这样做了)
    2. 编写您自己的视图以使用您的新模型类(基于 satchmo_store.contact.views,但使用您自己的类而不是 Contact 类)
    3. 覆盖 satchmo_store.contact 应用程序的 urlpatterns 以指向您的新视图
    4. 使用可编辑表单字段的条目扩展 satchmo_store.contact.forms.ExtendedContactInfoForm 表单类。
    5. 修改contact/view_profile.html 模板以包含自定义名称字段。

    那么您可能想像上面一样取消注册 Contact 类 admin.site.unregister(Contact),并且只管理您的新子类。

    【讨论】:

      【解决方案2】:

      听起来你做得对,但如果你发布你的来源会有所帮助。当我采用这条路线时,我将扩展配置文件视为用户模型的内联:

      class UserProfileInline(admin.StackedInline):
          model = UserProfile
          fk_name = 'user'
          max_num = 1
          fieldsets = [
              ('User Information', {'fields': ['street', 'street2', 'city', 'state', 'country', 'latitude', 'longitude']}),
              ('Site Information', {'fields': ['sites']}),
              ('User Account', {'fields': ['account_balance']}),
          ]
      
      class NewUserAdmin(admin.ModelAdmin):
          inlines = [UserProfileInline, ]
      
      admin.site.unregister(User)
      admin.site.register(User, NewUserAdmin)
      

      希望对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-30
        • 2012-03-11
        • 2010-12-26
        • 2015-07-08
        • 1970-01-01
        • 2018-01-26
        • 2016-07-29
        • 1970-01-01
        相关资源
        最近更新 更多