On Sat, May 25, 2013 at 5:07 PM, Nora Olsen <[email protected]> wrote:

> Hi,
>
> I have a user table that is not the default Django's User model. This
> table contains a list of users and their profiles for an API service that I
> host using Django/tastypie for a mobile app.
>
> They do have access to the portal that is built using Django.
>
> I'm trying to implement password reset for these mobile users. Is it
> possible to leverage on contrib.auth.views.password_reset but on a
> different table? Looking at code, it seems that is possible to do so by
> passing my own password_reset_form that use my own users table for mobile
> users?
>
> Hi Nora,

You're headed in the right direction, but the approach you've described
probably won't work. The password reset views themselves rely on being able
to query the User model, so you won't be able to just replace the forms -
you'd need to replace some of the internals of the views as well.

However, Django 1.5 gives you another approach. You can define a custom
user model [1] that matches your legacy table (using the db_table Meta
class option [2], and db_column field option [3]). This will provide a way
for Django to access your legacy User table, and allows all of Django's
tools (including the password reset tools) to access that table.

This way, you won't need to change the forms -- you just need to make sure
that you've got a User model that matches the basic Django user contract.

Depending on the properties of your existing User model, this might be
slightly complex -- in particular, Django's password reset token approach
requires a login-based timestamp, but not all user models will necessarily
have this. However, without additional details about your model, it's
difficult to provide any specific advice or guidance.

[1]
https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#substituting-a-custom-user-model
[2] https://docs.djangoproject.com/en/1.5/ref/models/options/#db-table
[3] https://docs.djangoproject.com/en/1.5/ref/models/fields/#db-column

Yours,
Russ Magee %-)

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to