views:

28

answers:

1

When I'm trying to create an extended user profile I'm getting UserProfile object is unsubscriptable. I've googled for solution, but 'your object is not a sequence' does not help here much. Here's the function I'm using, 'temp_data' is the data from my registration form :

def create_user(request):    
    data = request.session['temp_data']
    email = data['email']
    password1 = data['password1']
    userdata = {'email': email, 'password1': password1}
    backend = request.session['backend']
    #create User
    user = backend.register(request, userdata)
    data = UserProfile(user=user)
    data.is_active = False
    data.first_name = data['first_name']
    data.last_name = data['last_name']
    (... rest of the fields ...)
    data.save()

And my extended model :

class UserProfile(InheritedProfile):
    def upload_path(self, field_attname):
        filename = hashlib.md5(field_attname).hexdigest()[:4] + "_" + field_attname
        return settings.MEDIA_ROOT + "/uploads/users/%s" % (filename,)

    user = models.ForeignKey(User, unique=True, related_name='profile',)
    first_name = models.CharField(_("Name"), max_length=50, blank=False,)
    last_name = models.CharField(_("Surname"), max_length=50, blank=False,)
    street = models.CharField(_("Street"), max_length=50, blank=False,)
    code = models.CharField(_("Zip code"), max_length=6, blank=False,)
    city = models.CharField(_("City"), max_length=50, blank=False,) 
    image = models.ImageField(_("Avatar"), upload_to=upload_path, blank=True,)

And the Traceback :

File "/home/rails/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/rails/registration/views.py" in register_new
  115.     data.first_name = data['first_name']
+3  A: 

data = UserProfile(user=user) rebinds data. It cannot be both the model and the session data at the same time.

Ignacio Vazquez-Abrams
of course, you're right. thanks
muntu