models.py 618 B

1234567891011121314151617181920212223
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3. # Create your models here.
  4. from django.db.models.signals import post_save, post_delete
  5. from django.dispatch import receiver
  6. class UserProfile(models.Model):
  7. '''
  8. Extension for the default Django User model
  9. '''
  10. user = models.OneToOneField(User, on_delete=models.CASCADE)
  11. wallet = models.CharField(max_length = 128, blank=True, null=True)
  12. @receiver(post_save, sender=User)
  13. def create_user_profile(sender, instance, created, **kwargs):
  14. if created:
  15. UserProfile.objects.create(user=instance)