相关疑难解决方法(0)

将SQLite3迁移到MySQL的快速简便方法?

有人知道将SQLite3数据库迁移到MySQL的快捷方法吗?

mysql migration sqlite

216
推荐指数
14
解决办法
26万
查看次数

在django中使用distinct()和filter()

我正在尝试在 Django 中创建一个查询,该查询调用distinct满足过滤器某些条件(使用)的唯一行(使用filter

\n\n

这是使用的文件:

\n\n

视图.py

\n\n
def cat_details(request, pk):\n    current_user = request.user\n    selected_cat = get_object_or_404(Category, pk=pk)\n    selected_items = ItemIn.objects.all().filter(item_category=selected_cat).values_list(\'item_name\', flat=True).distinct()\n    all_cats = Category.objects.all()\n    cat_count = all_cats.count()\n    item_count = ItemIn.objects.values_list(\'item_name\', flat=True).distinct().count()  # returns a list of tuples..\n    #all_units = Item.objects.aggregate(Sum(\'item_quantity\'))[\'item_quantity__sum\']\n    context = {\n        #\'all_units\': all_units,\n        \'item_count\': item_count,\n        \'cat_count\': cat_count,\n        \'selected_items\': selected_items,\n        \'selected_cat\': selected_cat,\n        \'current_user\': current_user,\n    }\n\n    return render(request, \'townoftech_warehouse/cat_details.html\', context)\n
Run Code Online (Sandbox Code Playgroud)\n\n

调用的变量selected_items就是问题所在!

\n\n

这是我如何使用这个视图函数

\n\n

超文本标记语言

\n\n
{% extends \'townoftech_warehouse/base.html\' %}\n    {% block …
Run Code Online (Sandbox Code Playgroud)

python django

0
推荐指数
1
解决办法
3万
查看次数

标签 统计

django ×1

migration ×1

mysql ×1

python ×1

sqlite ×1