From af14cce3f87d0c5a9ba787990a82ae9221c9a4d9 Mon Sep 17 00:00:00 2001 From: reverend Date: Sun, 13 Sep 2020 15:49:15 +0200 Subject: [PATCH] Minor code restructuring --- lostplaces/lostplaces_app/models.py | 49 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/lostplaces/lostplaces_app/models.py b/lostplaces/lostplaces_app/models.py index c6b3ca1..6f95679 100644 --- a/lostplaces/lostplaces_app/models.py +++ b/lostplaces/lostplaces_app/models.py @@ -20,6 +20,30 @@ from taggit.managers import TaggableManager # Create your models here. +class Explorer(models.Model): + """ + Profile that is linked to the a User. + Every user has a profile. + """ + + user = models.OneToOneField( + User, + on_delete=models.CASCADE, + related_name='explorer' + ) + + def __str__(self): + return self.user.username + +@receiver(post_save, sender=User) +def create_user_profile(sender, instance, created, **kwargs): + if created: + Explorer.objects.create(user=instance) + +@receiver(post_save, sender=User) +def save_user_profile(sender, instance, **kwargs): + instance.explorer.save() + class Taggable(models.Model): ''' This abstract model represtens an object that is taggalble @@ -69,31 +93,6 @@ class Submittable(models.Model): related_name='%(class)s' ) -class Explorer(models.Model): - """ - Profile that is linked to the a User. - Every user has a profile. - """ - - user = models.OneToOneField( - User, - on_delete=models.CASCADE, - related_name='explorer' - ) - - def __str__(self): - return self.user.username - -@receiver(post_save, sender=User) -def create_user_profile(sender, instance, created, **kwargs): - if created: - Explorer.objects.create(user=instance) - -@receiver(post_save, sender=User) -def save_user_profile(sender, instance, **kwargs): - instance.explorer.save() - - class Voucher(models.Model): """ Vouchers are authorization tokens to allow the registration of new users.