Форум сайта python.su
Привет.
Есть вопрос по правильному созданию профиля пользователя после его регистрации.
models.py
class Profile(models.Model):
# user login
user = models.ForeignKey(User, unique=True)
# user tarif
tarif = models.ForeignKey(Tariff)
# active status
active = models.BooleanField(default=False)
@receiver(signals.user_profile,sender=User,dispatch_uid='user_profile')
def create_profile(sender,tarif,user,**kwargs):
Profile(user=user,tarif=tarif)
user_profile = django.dispatch.Signal(providing_args=['tarif'])
try:
tarif = Tarif.objects.get(slug=name)
except Tarif.DoesNotExist:
return redirect('tarif')
user_instance = form.save()
signals.user_profile.send(sender=User,tarif=tarif,user=user_instance)
@receiver(models.signals.post_save, sender=User)
def create_profile(sender,instance,signal,created,**kwargs):
# Как здесь получить tarif??
from apps.account.models import Profile
if created:
Profile(user=instance).save()
Отредактировано (Янв. 30, 2012 04:43:10)
Офлайн
ну, похоже на то, что в документации:
https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
Так-что скорее всего можете считать, что правильно.
Если есть желание, то можете сделать свой сигнал:
https://docs.djangoproject.com/en/1.3/topics/signals/#defining-and-sending-signals
Отредактировано (Янв. 30, 2012 06:48:35)
Офлайн