首页 > 其他分享 >使用了外键的models 结合 Modelviewset的写法

使用了外键的models 结合 Modelviewset的写法

时间:2022-11-26 15:56:33浏览次数:39  
标签:name models create Modelviewset 外键 Member time verbose

Serializers        重写create方法即可

class MemberSerializers(serializers.ModelSerializer):
    def create(self, validate):
        users = Member.objects.create(**validate)
        return users
    class Meta:
        model=Member
        exclude = ["create_time", "update_time"]

 

model

class Member(models.Model):
    """成员表"""
    name = models.CharField(max_length=30,verbose_name='姓名')
    nickname= models.CharField(max_length=30,verbose_name='Tapd的名字')
    department_id = models.IntegerField(verbose_name='部门')
    departmenttype = models.ForeignKey("DepartmentType",on_delete=models.CASCADE)
    occupation_id = models.IntegerField(verbose_name='职能')
    email = models.CharField(max_length=50,verbose_name='邮箱')
    create_time = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True,verbose_name='更新时间')

 

标签:name,models,create,Modelviewset,外键,Member,time,verbose
From: https://www.cnblogs.com/kaibindirver/p/16927569.html

相关文章