From a1d7b07e0c74fe7833b66d20c18e4897f6c1d2de Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 15 Oct 2017 21:19:13 +0200 Subject: [PATCH] Relate UserCardDetail with StripeCustomer and add more fields to uniquely identify if a user already has a card --- hosting/migrations/0044_usercarddetail.py | 11 ++++++----- hosting/models.py | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/hosting/migrations/0044_usercarddetail.py b/hosting/migrations/0044_usercarddetail.py index b935ab9a..458b3111 100644 --- a/hosting/migrations/0044_usercarddetail.py +++ b/hosting/migrations/0044_usercarddetail.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2017-10-15 18:05 +# Generated by Django 1.9.4 on 2017-10-15 19:17 from __future__ import unicode_literals -from django.conf import settings from django.db import migrations, models import django.db.models.deletion import utils.mixins @@ -11,7 +10,7 @@ import utils.mixins class Migration(migrations.Migration): dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('membership', '0006_auto_20160526_0445'), ('hosting', '0043_vmdetail'), ] @@ -20,11 +19,13 @@ class Migration(migrations.Migration): name='UserCardDetail', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('stripe_customer_id', models.CharField(max_length=100, unique=True)), ('last4', models.CharField(max_length=4)), ('brand', models.CharField(max_length=10)), + ('fingerprint', models.CharField(max_length=100)), + ('exp_month', models.IntegerField()), + ('exp_year', models.IntegerField()), ('preferred', models.BooleanField(default=False)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='membership.StripeCustomer')), ], options={ 'permissions': (('view_usercarddetail', 'View User Card'),), diff --git a/hosting/models.py b/hosting/models.py index a6fc0823..3efd6dd1 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -185,10 +185,12 @@ class VMDetail(models.Model): class UserCardDetail(AssignPermissionsMixin, models.Model): permissions = ('view_usercarddetail',) - user = models.ForeignKey(CustomUser) - stripe_customer_id = models.CharField(unique=True, max_length=100) + user = models.ForeignKey(StripeCustomer) last4 = models.CharField(max_length=4) brand = models.CharField(max_length=10) + fingerprint = models.CharField(max_length=100) + exp_month = models.IntegerField(null=False) + exp_year = models.IntegerField(null=False) preferred = models.BooleanField(default=False) class Meta: