from django.db import models
from django import forms
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import Profile

class Profile1(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')
    GENDER_CHOICES = (
           ("M", "Male"),
           ("F", "Female"),
           ("O", "Other")
      )
    gender = forms.ChoiceField(choices = GENDER_CHOICES)
    birth_date = models.DateField()

@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)


@receiver(post_save, sender=User)
def save_profile(sender, instance, created, **kwargs):
    instance.profile.save()
