Yes it help :), thanks!

W dniu piątek, 27 maja 2016 16:29:37 UTC+2 użytkownik Dariusz Mysior 
napisał:
>
> 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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/5fa41fca-3046-44ef-8d86-cf50729eea75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to