from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save


class ImagerProfile(models.Model):

    associated_user = models.OneToOneField(User)

    picture = models.FileField(blank=True)
    picture_privacy = models.BooleanField(default=True)

    phone_number = models.CharField(max_length=20, blank=True)
    phone_privacy = models.BooleanField(default=True)

    birthday = models.DateField(null=True, blank=True)
    birthday_privacy = models.BooleanField(default=True)

    name_privacy = models.BooleanField(default=True)
    email_privacy = models.BooleanField(default=True)

    def user(self):
        return self.associated_user.username

    def is_active(self):
        return self.associated_user.is_active

    @classmethod
    def active(self):
        qs = self.get_queryset()
        return qs.filter(associated_user__is_active=True)

    def create_profile(sender, **kwargs):
        if kwargs["created"]:
            ip = ImagerProfile(associated_user=kwargs["instance"])
            ip.save()


    post_save.connect(create_profile, sender=User)

@@ -112,16 +112,29 @@
 ost_save
+, post_delete
 %0A%0A%0Aclass
@@ -1088,35 +1088,251 @@
 ()%0A%0A
-%0A    post_save.connect(crea
+    def delete_profile(sender, **kwargs):%0A        if kwargs%5B%22created%22%5D:%0A            ip = ImagerProfile(associated_user=kwargs%5B%22instance%22%5D)%0A            ip.delete()%0A%0A    post_save.connect(create_profile, sender=User)%0A    post_delete.connect(dele
 te_p

initialize delete_profile method.