Can't update extended user django model

81 views
Skip to first unread message

Info Test

unread,
Jul 21, 2015, 3:55:19 AM7/21/15
to django...@googlegroups.com
When I save my model, there is no effect in database.
What is the problem?

class Profil(models.Model):
    user = models.OneToOneField(User)


in manage.py shell

>>> p = models.Profil.objects.get(user__username='testname')

>>> p.user.is_superuser
False
>>> p.user.is_superuser = True
>>> p.user.is_superuser
True
>>> exit()
>>> p = models.Profil.objects.get(user__username='testname')
>>> p.user.is_superuser

False ---------> ????????????????????????????????


Info Test

unread,
Jul 21, 2015, 4:02:38 AM7/21/15
to django...@googlegroups.com


Le mardi 21 juillet 2015 10:55:19 UTC+3, Info Test a écrit :
When I save my model, there is no effect in database.
What is the problem?

class Profil(models.Model):
    user = models.OneToOneField(User)


in manage.py shell

>>> p = models.Profil.objects.get(user__username='testname')

>>> p.user.is_superuser
False
>>> p.user.is_superuser = True
>>> p.save()

James Schneider

unread,
Jul 21, 2015, 4:04:52 AM7/21/15
to django...@googlegroups.com

You didn't call p.save() anywhere, so the change you made wasn't committed to the database. All you've done here is made a change to the object in memory you pulled out of the database, and then over wrote that change by pulling another copy out of the database.

-James

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/df7490d5-108e-4960-b80b-8071662d8db1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Info Test

unread,
Jul 21, 2015, 4:43:08 AM7/21/15
to django...@googlegroups.com
Even with p.save(force_update = True) , it doesn't work

James Schneider

unread,
Jul 21, 2015, 4:54:33 AM7/21/15
to django...@googlegroups.com

Are you getting any sort of error when you run save()? Are the changes reflected in the database after the save() call? Can you perform the same operation directly on the user object?

Also, this operation shouldn't require any arguments to save().

-James

On Jul 21, 2015 1:43 AM, "Info Test" <infot...@gmail.com> wrote:
Even with p.save(force_update = True) , it doesn't work

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Info Test

unread,
Jul 21, 2015, 5:07:49 AM7/21/15
to django...@googlegroups.com
Any error appear on console, is it possible that only superuser can do that?

Sadaf Noor

unread,
Jul 21, 2015, 5:37:59 AM7/21/15
to django...@googlegroups.com
Did you "python manage.py migrate"?

2015-07-21 15:07 GMT+06:00 Info Test <infot...@gmail.com>:
Any error appear on console, is it possible that only superuser can do that?

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
 Md. Sadaf Noor (@sadaf2605)
 www.sadafnoor.com

Info Test

unread,
Jul 21, 2015, 5:50:38 AM7/21/15
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages