Я настроил нечто подобное ранее. В моем случае я определял новых пользователей через интерфейс администратора, но основная проблема была та же. Мне нужно было показать определенную страницу (т.е. пользовательские настройки) при первом входе в систему.
Я закончил тем, что добавил флаг (first_log_in, BooleanField) в модель UserProfile. Я установил проверку для этого в функции просмотра моей главной страницы, которая обрабатывает маршрутизацию. Вот грубая идея.
views.py:
def get_user_profile(request):
# this creates user profile and attaches it to an user
# if one is not found already
try:
user_profile = request.user.get_profile()
except:
user_profile = UserProfile(user=request.user)
user_profile.save()
return user_profile
# route from your urls.py to this view function! rename if needed
def frontpage(request):
# just some auth stuff. it's probably nicer to handle this elsewhere
# (use decorator or some other solution :) )
if not request.user.is_authenticated():
return HttpResponseRedirect('/login/')
user_profile = get_user_profile(request)
if user_profile.first_log_in:
user_profile.first_log_in = False
user_profile.save()
return HttpResponseRedirect('/profile/')
return HttpResponseRedirect('/frontpage'')
models.py:
from django.db import models
class UserProfile(models.Model):
first_log_in = models.BooleanField(default=True, editable=False)
... # add the rest of your user settings here
Важно, чтобы вы установили AUTH_PROFILE_MODULE в своем файле setting.py, чтобы указать модель. Т.е..
AUTH_PROFILE_MODULE = 'your_app.UserProfile'
должно работать.
Взгляните на эту статью для получения дополнительной информации о UserProfile. Надеюсь, это поможет. :)