I try update my photo in avatar field but it not save changes, please look 
on it

update_form.html

{% extends 'base.html' %}
{% block title %}Edycja profilu{% endblock %}


{% if user.is_authenticated %}
    {% block top_menu %}
    <a href="{% url 'myprofile:profile-view' %}">{{ user.username }}</a>
    <a href="{% url 'users:logout-view' %}">Wyloguj siÄ™</a>
    {% endblock %}

{% block content %}
    <form action="" method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <input type="submit" value="zapisz" />
    </form>
{% endblock %}
{% else %}

{% endif %}


views.py

from django.shortcuts import render
from django.views.generic import TemplateView, UpdateView
from users.models import MysiteUser

class ProfileView(TemplateView):
    template_name = 'profile.html'

class EditView(UpdateView):
    model = MysiteUser
    fields = ['avatar']
    pk_url_kwarg = 'pk'
    template_name = 'update_form.html'
    success_url = '/myprofile/'

    def form_valid(self, form):
        self.object = form.save()
        return super(EditView,self).form_valid(form)


models.py

from django.db import models
from django.contrib.auth.models import AbstractUser

##################################################

class MysiteUser(AbstractUser):
    avatar = models.ImageField(upload_to="avatar")

    def __str__(self):
        return self.username



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/968faf01-3b6b-43d8-8c98-d1555d48ee4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to