• 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. 秘钥 对中 ,让大家知道的是公钥,不要告诉大家只有自己知道的是私钥。

     

     

  • 相关阅读:
    计算公司下班时间(娱乐)
    设计模式-观察者模式
    vue 打包后白屏的问题
    HashSet实现原理
    LinkedList实现原理
    ArrayList的实现原理
    HashMap实现原理分析
    深入理解java动态代理机制
    Spring工作原理
    数据库SQL优化大总结之 百万级数据库优化方案
  • 原文地址:https://www.cnblogs.com/mengbin0546/p/9280602.html
Copyright © 2020-2023  润新知