django update_or_create
摘要:update_or_create question.votes.update_or_create(user=request.user, defaults={"value": value}) # user 为查询条件 # defaults 中的数据如果存着就更新, 不存着就创建这条数据
阅读全文
django获取某一个字段的列表 values values_list flat=true
摘要:1.values() print(Question.objects.values('title')) #得到的是一个字典 <QuestionQuerySet [{'title': '查询优化之select_related与prefetch_related - 简书'}, {'title': '你们都
阅读全文
Django之ContentType,GenericRelation, GenericForeignKey
摘要:contenttypes 是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中。 models.py文件的表结构写好后,通过makemigrations和migrate两条命令迁移数据后,在数据库中会自动生成一个django_content
阅读全文