Reputation:
I have added one additional field, network
, in django-registration.
# in myproject.userprofile
from django.db import models
from django.contrib.auth.models import User
from myproject.network.models import Network
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
network = models.ForeignKey(Network, unique=True)
# in settings.py
AUTH_PROFILE_MODULE = 'userprofile.UserProfile'
I don't need to add anything new to forms, as the network is generated based on the user's authorized email address.
So far, I have the following -- which is working, but is obviously not the best way to do it --
profile_additional = UserProfile.objects.create(user=User.objects.get(username=username),network=Network.objects.get(network=EmailList.objects.get(email=email).network))
Could you please show me the preferred way to do this same thing? I've read a couple tutorials on adding additional fields using signals, but can't seem to get it working myself. A code demonstrating how to do this would be much appreciated. Thank you.
Upvotes: 1
Views: 1577
Reputation: 18982
This is an example that shows you how to use signals to create a new profile if needed.
You can easily extend the example to edit your network field when your profile ist created or to check wether the network field is set every time a user is saved.
Upvotes: 1