Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django rest framework viewset perform_update

def perform_update(self, serializer):
    # Save with the new value for the target model fields
    user = self.request.user
    userid = str(user.id)
    serializer.save(stu_enrolled_classes=userid)
# The above def is in viewset and you can specify what field else can be edited in the API "PUT",
# Here We just set the stu_enrolled_classes field with is relation to the user to be the current user that send the "PUT" request.
Comment

django rest framework viewset

class UserViewSet(viewsets.ModelViewSet):
    """
    A viewset for viewing and editing user instances.
    """
    serializer_class = UserSerializer
    queryset = User.objects.all()
Comment

call update in create method django viewset

# call this code from create method with a pk to update (if exists)
self.kwargs["pk"] = str(query_set[0].pk)
return self.update(request, *args, **kwargs)
Comment

PREVIOUS NEXT
Code Example
Python :: postgresql backup using python 
Python :: python contextmanager 
Python :: python how to draw a circle 
Python :: python get numbers after decimal point 
Python :: check status code urllib open 
Python :: pyton count number of character in a word 
Python :: how to access http page in pythion 
Python :: python regex search a words among list 
Python :: python counter nested dictionary 
Python :: check for string in list py 
Python :: calculate pointbiseral correlation 
Python :: seaborn color palette python 
Python :: flask session auto logout in 5 mins 
Python :: pandas read csv without scientific notation 
Python :: pandas astype str still object 
Python :: ubuntu 20.10 python 3.8 
Python :: use mongo replica set python 
Python :: best python gui for desktop application 
Python :: enumerate items python 
Python :: python get screen size raspberry pi 
Python :: flask api 
Python :: append multiple values to 2d list python 
Python :: get method in python 
Python :: send api request python 
Python :: console-based animation-simple 
Python :: find max number in list python 
Python :: length of a string python 
Python :: how to append number in tuple 
Python :: selenium ways of finding 
Python :: turtle 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =