Browse Source

Profile and Subscription managers use get_or_create to avoid some boilerplate

pull/50/head
Pēteris Caune 9 years ago
parent
commit
bb193cf4f1
2 changed files with 2 additions and 12 deletions
  1. +1
    -6
      hc/accounts/models.py
  2. +1
    -6
      hc/payments/models.py

+ 1
- 6
hc/accounts/models.py View File

@ -16,12 +16,7 @@ from hc.lib import emails
class ProfileManager(models.Manager):
def for_user(self, user):
try:
profile = self.get(user_id=user.id)
except Profile.DoesNotExist:
profile = Profile(user=user)
profile.save()
profile, created = Profile.objects.get_or_create(user_id=user.id)
return profile


+ 1
- 6
hc/payments/models.py View File

@ -5,12 +5,7 @@ from django.db import models
class SubscriptionManager(models.Manager):
def for_user(self, user):
try:
sub = self.get(user_id=user.id)
except Subscription.DoesNotExist:
sub = Subscription(user=user)
sub.save()
sub, created = Subscription.objects.get_or_create(user_id=user.id)
return sub


Loading…
Cancel
Save