queryset

https://blog.csdn.net/miaoqinian/article/details/81174707?tdsourcetag=s_pctim_aiomsg
列表转queryset
``

queryset = A.objects.filter(user=user)
        a = []
        for quiza in queryset:
            if search in quiza.title.title:
                a.append(quiza)
        queryset = UserQuizFree.objects.filter(pk__in=[x.pk for x in a])
    else:
        queryset = UserQuizFree.objects.filter(user=user).order_by('-id')

queryset 转 json
``

	from django.core import serializers	
	json.loads(serializers.serialize('json', queryset))
	----------------------------------------------
	queryset.values()

多对多字段添加和删除

class A(models.Model):
       people = ManyToManyField()
 添加:
	obj. people.add(xxx)     # 添加一个
	obj.set(queryset)     # 重新赋值
 删除:
 	obj.people.remove(xxx)

外键和多对多反查

cluster.basicinfo_set.all()
如果 Basicinfo 中的某个字段 对多对多到 Cluster,且related_name,, 是不可以这样反查的

你可能感兴趣的:(queryset)