day106 支付功能与优惠券功能

  https://blog.csdn.net/Ayhan_huang/article/details/78626957

一、ContenType

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey,GenericRelation
# Create your models here.
class Electrics(models.Model):
    name =models.CharField(max_length=32)
    price =models.IntegerField(default= 100)
    coupons =GenericRelation(to ="Coupon")

    def __str__(self):
        return self.name

class Clothes(models.Model):
    name =models.CharField(max_length=32)
    price =models.IntegerField(default= 50 )
    coupon =GenericRelation(to ="Coupon")

    def __str__(self):
        return self.name


class Foods(models.Model):
    name =models.CharField(max_length=32)
    price =models.IntegerField(default=20)
    coupons =GenericRelation(to="Coupon")

    def __str__(self):
        return self.name

class Coupon(models.Model):
    name = models.CharField(max_length=32)

    content_type =models.ForeignKey(to=ContentType) #step 1
    object_id =models.PositiveIntegerField() #step 2
    content_object =GenericForeignKey("content_type","object_id") # step 3

    def __str__(self):
        return self.name



    # electics_obj =models.ForeignKey(to = "Foods",null=True)
    # food_obj =models.ForeignKey(to ="Foods",null=True)
    # cloth_obj =models.ForeignKey(to="Clothes",null=True)

"""
  Coupon 
  
     id  name            content_type_id          object_id
     1   冰箱满减优惠         
  
"""

views

from django.shortcuts import render,HttpResponse
from App01 import models
# Create your views here.


def  index(request):
    # 为三星电视(id=2)创建一条优惠记录
    # s_bingxiang = models.Electrics.objects.filter(id=2).first()
    # models.Coupon.objects.create(name='电冰箱优惠券', content_object=s_bingxiang)
    # models.Coupon.objects.create(name='猪蹄优惠券', content_type_id=10, object_id=1)

    #查询猪蹄买一送一优惠券对应商品的价格
    coupon =models.Coupon.objects.filter(name="猪蹄优惠券").first()


    #美的冰箱所有优惠券的名字
    meidi=models.Electrics.objects.filter(name ="美的冰箱").first()
    return HttpResponse("ok")

  

二、支付宝接口

扫描二维码关注公众号,回复: 1948576 查看本文章

1.私钥是不能公开,一个公钥对应一个私钥。

2. 秘钥 对中 ,让大家知道的是公钥,不要告诉大家只有自己知道的是私钥。

 

 

猜你喜欢

转载自www.cnblogs.com/mengbin0546/p/9280602.html
今日推荐