↓↓クリックして頂けると励みになります。
【49 | 支払いページ】 << 【ホーム】 >> 【51 | PayPalアカウント】
「core/models.py」ファイルを編集します。
記述編集 【Desktop/crowdsource/core/models.py】
import uuid from django.db import models from django.contrib.auth.models import User from django.utils import timezone # Create your models here. class Customer(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) avatar = models.ImageField(upload_to='customer/avatars/', blank=True, null=True) phone_number = models.CharField(max_length=50, blank=True) stripe_customer_id = models.CharField(max_length=255, blank=True) stripe_payment_method_id = models.CharField(max_length=255, blank=True) stripe_card_last4 = models.CharField(max_length=255, blank=True) def __str__(self): return self.user.get_full_name() class Courier(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) lat = models.FloatField(default=0) lng = models.FloatField(default=0) paypal_email = models.EmailField('PayPalメールアドレス', max_length=255, blank=True) def __str__(self): return self.user.get_full_name() class Category(models.Model): slug = models.CharField(max_length=255, unique=True) name = models.CharField(max_length=255) def __str__(self): return self.name class Job(models.Model): SMALL_SIZE = "small" MEDIUM_SIZE = "medium" LARGE_SIZE = "large" SIZES = ( (SMALL_SIZE, '小'), (MEDIUM_SIZE, '中'), (LARGE_SIZE, '大'), ) CREATING_STATUS = 'creating' PROCESSING_STATUS = 'processing' PICKING_STATUS = 'picking' DELIVERING_STATUS = 'delivering' COMPLETED_STATUS = 'completed' CANCELED_STATUS = 'canceled' STATUSES = ( (CREATING_STATUS, 'Creating'), (PROCESSING_STATUS, 'Processing'), (PICKING_STATUS, 'Picking'), (DELIVERING_STATUS, 'Delivering'), (COMPLETED_STATUS, 'Completed'), (CANCELED_STATUS, 'Canceled'), ) # Step 1 id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) customer = models.ForeignKey(Customer, on_delete=models.CASCADE, verbose_name='配達依頼人') courier = models.ForeignKey(Courier, on_delete=models.CASCADE, null=True, blank=True) name = models.CharField('配達依頼名', max_length=255) description = models.CharField('備考', max_length=255) category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, verbose_name='カテゴリー') size = models.CharField('サイズ', max_length=20, choices=SIZES, default=MEDIUM_SIZE) quantity = models.IntegerField('数量', default=1) photo = models.ImageField('写真', upload_to='job/photos/') status = models.CharField('状態', max_length=20, choices=STATUSES, default=CREATING_STATUS) created_at = models.DateTimeField(default=timezone.now, verbose_name='登録日') # Step 2 pickup_address = models.CharField('荷物受取先住所', max_length=255, blank=True) pickup_lat = models.FloatField('依頼人緯度', default=0) pickup_lng = models.FloatField('依頼人経度', default=0) pickup_name = models.CharField('依頼人氏名', max_length=255, blank=True) pickup_phone = models.CharField('依頼人電話番号', max_length=50, blank=True) # Step 3 delivery_address = models.CharField('配達先住所', max_length=255, blank=True) delivery_lat = models.FloatField('配達先緯度', default=0) delivery_lng = models.FloatField('配達先経度',default=0) delivery_name = models.CharField('配達先氏名',max_length=255, blank=True) delivery_phone = models.CharField('配達先電話番号',max_length=50, blank=True) # Step 4 duration = models.IntegerField('移動時間' ,default=0) distance = models.FloatField('距離' ,default=0) price = models.IntegerField('料金', default=0) # その他 pickup_photo = models.ImageField(upload_to='job/pickup_photos/', null=True, blank=True) pickedup_at = models.DateTimeField(null=True, blank=True) delivery_photo = models.ImageField(upload_to='job/delivery_photos/', null=True, blank=True) delivered_at = models.DateTimeField(null=True, blank=True) def __str__(self): return self.description class Transaction(models.Model): IN_STATUS = "in" OUT_STATUS = "out" STATUSES = ( (IN_STATUS, 'In'), (OUT_STATUS, 'Out'), ) stripe_payment_intent_id = models.CharField(max_length=255, unique=True) job = models.ForeignKey(Job, on_delete=models.CASCADE) amount = models.FloatField(default=0) status = models.CharField(max_length=20, choices=STATUSES, default=IN_STATUS) created_at = models.DateTimeField(default=timezone.now) def __str__(self): return self.stripe_payment_intent_id
マイグレーションファイルを作成します。
コマンド
python manage.py makemigrations
マイグレーションを適用します。
コマンド
python manage.py migrate
「core/admin.py」ファイルを編集します。
記述編集 【Desktop/crowdsource/core/admin.py】
from django.contrib import admin from . import models class TransactionAdmin(admin.ModelAdmin): list_display = ['stripe_payment_intent_id', 'courier_paypal_email', 'customer', 'courier', 'job', 'amount', 'status', 'created_at'] list_filter = ['status',] def customer(self, obj): return obj.job.customer def courier(self, obj): return obj.job.courier def courier_paypal_email(sefl, obj): return obj.job.courier.paypal_email if obj.job.courier else None # Register your models here. admin.site.register(models.Customer) admin.site.register(models.Courier) admin.site.register(models.Category) admin.site.register(models.Job) admin.site.register(models.Transaction, TransactionAdmin)
管理サイトの表示を確認します。
http://127.0.0.1:8000/admin/core/transaction/
↓↓クリックして頂けると励みになります。
【49 | 支払いページ】 << 【ホーム】 >> 【51 | PayPalアカウント】