I having a error "expected string or buffer" when submit to upload avatar 
when edit profile. Can't figure out what is the problem..

*Model:*
class MyProfile(models.Model):
    user = models.ForeignKey(User)
    dob = models.DateField(null=True, blank=True)
    address = models.CharField(max_length=100, blank=True)
    contact = models.CharField(max_length=50, blank=True)
    bio = models.TextField(blank=True)
    avatar_url = FileField(_("Avatar"), max_length=200, format="Image", 
upload_to='user/avatar', blank=True)
    banner_url = FileField(_("Cover"), max_length=200, format="Image", 
upload_to='user/cover', blank=True)
    created = models.DateTimeField(auto_now_add=True)
    last_modified = models.DateTimeField(auto_now=True)

*Forms:*
class UserModelForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ('first_name', 'last_name', 'email')
        widgets = {
            'email': forms.TextInput(attrs={'readonly':'readonly'}),
        }


class UserProfileModelForm(forms.ModelForm):
    dob = forms.DateField(widget=forms.DateInput(format = '%d/%m/%Y'), 
                               input_formats=('%d/%m/%Y',), 
                               required=True, help_text='dd/mm/yyyy')
    avatar_url = forms.FileField()

    class Meta:
        model = MyProfile
        fields = ('dob', 'address', 'contact', 'bio', 'avatar_url')


*Views:*
def editProfileView(request, template="controlpanel/cp_edit_profile.html"):

    myprofiles = MyProfile.objects.all()
    myprofile = get_object_or_404(myprofiles, user=request.user)

    if request.method == "POST":
        form = UserProfileModelForm(request.POST, request.FILES, instance=
myprofile)
        userForm = UserModelForm(request.POST, request.FILES, instance=
request.user)

        if form.is_valid() and userForm.is_valid():
            user = userForm.save()
            profile = form.save(commit = False)
            profile.user = user
            profile.save()


            info(request, _("Successfully Edit"))
    else:
        userForm = UserModelForm(instance=request.user)
        form = UserProfileModelForm(instance=myprofile)


    context = {"cpprofile": myprofile, 'userForm':userForm, 'form':form}

    return render(request, template, context)


Thank you in advance...

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to