How to use Django models with enumeration in REST APIs?

I am using User model to store user details:

class User(models.Model):
    name = models.CharField(max_length=255)
    email = models.EmailField(unique=True)
    phone = models.CharField(max_length=255)
    membership = models.CharField(max_length=1, choices=MEMBERSHIP_CHOICES, default=MEMBERSHIP_BRONZE)

When customer created using post api then i want to allow only these three values Bronze for MEMBERSHIP_BRONZE, Silver for MEMBERSHIP_SILVER & Gold for MEMBERSHIP_GOLD in membership field. When a user select membership choices lebel from ui then i need to insert the respected value. I don't know how to do this?

class UserSerializer(serializers.ModelSerializer):

    class Meta:
    model = User
    fields = ["name", "email", "phone", "membership"]

@api_view(["GET", "POST", "PUT"])
def userActions(request):
    if request.method == "GET":
        users = User.objects.all()
        serializer = UserSerializer(users, many=True)
        res =
    if request.method == "POST":
        name = request.POST.get("name")
        email =
        phone = request.POST.get("phone")
        membership = request.POST.get("membership")
        user = User.objects.create(name=name, email=email, phone=phone, membership=membership)
        serializer = UserSerializer(user)
        res =
    return res
Back to Top