Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango rest framework ModelSerializer
    text
    copied!<p>Django rest framework <a href="http://django-rest-framework.org/api-guide/serializers#modelserializer" rel="nofollow">ModelSerializer</a></p> <p>How to use <a href="http://django-rest-framework.org/api-guide/serializers#modelserializer" rel="nofollow">ModelSerializer</a> with <a href="https://docs.djangoproject.com/en/1.6/ref/contrib/auth/" rel="nofollow">User</a>.</p> <p>I just tried <a href="http://django-rest-framework.org/tutorial/quickstart" rel="nofollow">quickstart</a>.</p> <p>And it was good. But password is saved on the plain text.</p> <pre><code>$ pip freeze Django==1.6 argparse==1.2.1 djangorestframework==2.3.9 wsgiref==0.1.2 $ curl -X post -d "username=lee&amp;password=test" http://localhost:8081/users/ {"id": 4, "password": "test", "last_login": "2013-11-26T08:12:06.166Z", "is_superuser": false, "username": "lee", "first_name": "", "last_name": "", "email": "", "is_staff": false, "is_active": false, "date_joined": "2013-11-26T08:12:06.167Z", "groups": [], "user_permissions": []} $ python manage.py shell Python 2.7.3 (default, Sep 26 2013, 20:03:06) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) &gt;&gt;&gt; &gt;&gt;&gt; &gt;&gt;&gt; &gt;&gt;&gt; from django.contrib.auth.models import User &gt;&gt;&gt; user=User.objects.get(username='lee') &gt;&gt;&gt; user.password u'test' &gt;&gt;&gt; </code></pre> <p>Maybe <a href="http://django-rest-framework.org/api-guide/serializers#modelserializer" rel="nofollow">ModelSerializer</a> isn't use <a href="https://github.com/django/django/blob/1.6/django/contrib/auth/models.py#L234" rel="nofollow">set_password</a>.</p> <p>So... What should I do in order to use <a href="https://github.com/django/django/blob/1.6/django/contrib/auth/models.py#L234" rel="nofollow">set_password</a> in <a href="http://django-rest-framework.org/api-guide/serializers#modelserializer" rel="nofollow">ModelSerializer</a>?</p> <hr> <p>[EDIT]</p> <p>Thank you for your answering~!</p> <p>BTW, I have a question.</p> <p>I think your code is something wrong.</p> <p><a href="https://gist.github.com/meoooh/7659801#file-gistfile1-py-L17" rel="nofollow">https://gist.github.com/meoooh/7659801#file-gistfile1-py-L17</a></p> <p>User object is not created yet. But it call get_object in line 17.</p> <p>So I think something is little bit awkward.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload