Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

updating many to many field in django using pk

#if you have **list of pk** for new m2m objects

today_ref_pk = [1,2,3]
u = MyUser.objects.get(pk=1)
u.today_ref_viewed_ips.clear()
u.today_ref_viewed_ips.add(*today_ref_pk)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #updating #field #django #pk
ADD COMMENT
Topic
Name
8+5 =