MY model
class XP(models.Model):
    bizuser = models.ForeignKey(BizUser, on_delete=models.CASCADE)
    current_xp_price = models.IntegerField(default=0)
    xp_created_at = models.DateTimeField(auto_now_add=True)
    xp_updated_at = models.DateTimeField(auto_now_add=True)

i have this function that creates an XP i want if the current user is 
authenticated(jwttokens) the user can then go ahead to create the XP .when 
i go to post this data i get to fields that i have to fill that is  
current_xp_price 
and  bizuser which is a  ForeignKey  how do you automatically fill this 
field (bizuser)ForeignKey rather than having to look for bizuser ID
  
Views

class create_xp(APIView):
    def post(self, request):
        if request.user.is_authenticated:
            current_user = request.BizUser
            serializer = XPSerializer(data=request.data)
            request.data["bizuser"] = current_user.id

            if serializer.is_valid():
                serializer.save()
                return Response(serializer.data, 
status=status.HTTP_201_CREATED)
            return Response(serializer.errors, 
status=status.HTTP_400_BAD_REQUEST)
        else:
            return Response(status=status.HTTP_401_UNAUTHORIZED)

serializers

class XPSerializer(serializers.ModelSerializer):
    class Meta:
        model = XP
        fields = ['current_xp_price', ]

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ffaa3804-6274-4148-b2ff-111a753aa207n%40googlegroups.com.

Reply via email to