zoukankan      html  css  js  c++  java
  • day106 支付功能与优惠券功能 contentype

      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")
    

      

    二、支付宝接口

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

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

     

     

  • 相关阅读:
    BZOJ 3506 机械排序臂 splay
    BZOJ 2843 LCT
    BZOJ 3669 魔法森林
    BZOJ 2049 LCT
    BZOJ 3223 文艺平衡树 splay
    BZOJ 1433 假期的宿舍 二分图匹配
    BZOJ 1051 受欢迎的牛 强连通块
    BZOJ 1503 郁闷的出纳员 treap
    BZOJ 1096 ZJOI2007 仓库设计 斜率优化dp
    BZOJ 1396: 识别子串( 后缀数组 + 线段树 )
  • 原文地址:https://www.cnblogs.com/mengbin0546/p/9280602.html
Copyright © 2011-2022 走看看