Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extending satchmo user profile

I'm trying to extend the basic user registration form and profile included in satchmo store, but I'm in problems with that.

This what I've done:

Create a new app "extendedprofile"

Wrote a models.py that extends the satchmo_store.contact.models class and add the custom name fields.

wrote an admin.py that unregister the Contact class and register my newapp but this still showing me the default user profile form.

Maybe some one can show me the correct way to do this?

like image 950
z3a Avatar asked Oct 14 '22 05:10

z3a


2 Answers

It sounds like you are doing it right, but it would help if you post your source. When I take this route, I treat the extended profile as an inline to the user model:

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)

Hopefully that helps you.

like image 65
Luke Avatar answered Oct 21 '22 03:10

Luke


Wrote a models.py that extends the satchmo_store.contact.models class and add the custom name fields.

wrote an admin.py that unregister the Contact class and register my newapp but this still showing me the default user profile form.

This is related to overriding the django registration User class; the satchmo project creates a foreign key to the User class (as of 0.9.2). But what you want to do is create an extended profile class with new fields.

So, in this specific case you're going to need to do a few things to override the profile template that shows the Contact information:

  1. Write your own models that subclass the Contact class (you already did this)
  2. Write your own view(s) to use your new model class (base on satchmo_store.contact.views but use your own class instead of the Contact class)
  3. Override the urlpatterns for the satchmo_store.contact application to point at your new view
  4. Extend the satchmo_store.contact.forms.ExtendedContactInfoForm form class with entries for your editable form fields.
  5. Modify the contact/view_profile.html template to include the custom name fields.

Then you may want to unregister the Contact class as above, admin.site.unregister(Contact), and only admini your new subclass.

like image 40
tmarthal Avatar answered Oct 21 '22 03:10

tmarthal