Reputation: 259
Everything is working in the code but its not storing data.Even user is getting redirected with HTTPResponseRedirect but its not storing data.If there is any other way to update my UserProfile
Views.py
@login_required
def p1details(request):
if request.method == 'POST':
#form=p1detailsform(data=request.POST)
script = request.POST.get('script')
request.user.info = script
request.user.save()
print("cmon")
return HttpResponseRedirect('/harpoons/dashboard')
else:
return render(request, 'p1details.html', {})
Models.py
class UserProfile(models.Model):
# This line is required. Links UserProfile to a User model instance.
user = models.OneToOneField(User)
GENRE_CHOICES = (
('m', 'Masculino'),
('f', 'Feminino'),
)
# The additional attributes we wish to include.
website = models.URLField(blank=True,)
info = models.CharField(max_length=30,blank=True)
birth_date = models.DateField(null=True)
genre = models.CharField(max_length=1, choices=GENRE_CHOICES, null=True)
script = models.TextField(max_length=None, null=True)
#my_field = tinymce_models.HTMLField(max_length=None, null=True)
docfile = models.FileField(upload_to='documents/%Y/%m/%d', null=True)
def __unicode__(self):
return self.user.username
Template
<form method="post" action="{% url 'harpoons:p1details' %}">
{% csrf_token %}
<input type="text" name="script">kuch bhar
<input type="submit" name="submit" value="Provide details" />
</form>
Upvotes: 0
Views: 28
Reputation: 2798
You are trying to save a user object instead of userprofile object
request.user.userprofile.info = script
request.user.userprofile.save()
Upvotes: 1
Reputation: 444
Actual you should use form for validation data. In this case:
request.user.userprofile.info = script
request.user.userprofile.save()
Upvotes: 1