UpdateView - problem with change model

14 views
Skip to first unread message

Dariusz Mysior

unread,
May 28, 2016, 2:14:00 PM5/28/16
to Django users
I have that problem when I change model in view class EditView on PersonalInfo I have response that "Not found personal info that meet your criteria" when I have model = MysiteUser than it is ok but when I change on model = PersonalInfo than it's a problem.

views.py

from django.contrib.messages.views import SuccessMessageMixin
from django.views.generic import TemplateView, UpdateView
from users.models import MysiteUser, PersonalInfo

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

class EditView(SuccessMessageMixin, UpdateView):
    model = PersonalInfo
    fields = ['age']
    pk_url_kwarg = 'pk'
    template_name = 'update_form.html'
    success_url = '/myprofile/'
    success_message = "Zmiany zostały wprowadzone."

models.py

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

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

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

    def __str__(self):
        return self.username

class PersonalInfo(models.Model):
    mysiteuser = models.OneToOneField(MysiteUser)
    age = models.IntegerField()



Akhil Lawrence

unread,
May 28, 2016, 10:20:28 PM5/28/16
to Django users
Check the primary key you are passing in the URL while calling the view. Key of PersonalInfo need not to be the same as that of MySiteUser
Reply all
Reply to author
Forward
0 new messages