I am in Django 1.11 and my question is quite simple :
I read these posts :
- Extending the User model with custom fields in Django
- https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html
and I am not sure a StudentCollaborator user will be created/updated when a user exists (there is already users in the database so I cannot simply redo stuff ).
My current code looks like this :
# Create your models here.
class StudentCollaborator(models.Model):
# https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model
user = models.OneToOneField(User, on_delete=models.CASCADE)
"""" code postal : pour l'instant que integer"""
code_postal = models.IntegerField(null=True, blank=False)
"""" flag pour dire si l'user a activé le système pour lui """
collaborative_tool = models.BooleanField(default=False)
""" Les settings par défaut pour ce user """
settings = models.ForeignKey(CollaborativeSettings)
def change_settings(self, new_settings):
self.settings = new_settings
self.save()
""" https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html#onetoone """
""" Signaux: faire en sorte qu'un objet StudentCollaborator existe si on a un modele """
@receiver(post_save, sender=User)
def create_student_collaborator_profile(sender, instance, created, **kwargs):
if created:
""" On crée effectivement notre profile """
StudentCollaborator.objects.create(
user=instance,
collaborative_tool=False,
settings=CollaborativeSettings.objects.create() # Initialisé avec les settings par défaut
)
Can you help me ?
Thanks