Django Rest Framework中用户数据库的最佳模型是什么?

时间:2016-12-06 21:08:30

标签: python django-models django-rest-framework

我刚开始学习DRF,我想知道为用户构建模型的最佳方法是什么。我想将我的其余API数据提供给移动设备,因此从API中获取特定字段至关重要。是否可以嵌套在同一模型中,并为ID为1的数据集检索“电子邮件”?

serializers.py

from .models import UserDatabase
from rest_framework import serializers

class UserDatabaseSerializer(serializers.ModelSerializer):
    """
    Serializing the user database with our fields
    Adding them directly to the database
    """

    class Meta:
        model = UserDatabase
        fields = ("id","email","first_name","last_name","passw")

models.py

from django.db import models
class UserDatabase(models.Model):
    """
    """
    id = models.IntegerField(primary_key=True)
    email = models.CharField(max_length=320)
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    passw = models.CharField(max_length=60)

编辑我想说的是,我的模型和序列化程序应该如何查看,以便在通过查询他的“id”找到用户后能够查询特定字段,如“email”

0 个答案:

没有答案