class warehousePeopleBase(ModelAdmin): model = warehousePeople menu_label = '库房人员出入库信息' # ditch this to use verbose_name_plural from model menu_icon = 'site' # change as required list_display = ['name', 'month', 'warehouse', 'subjectMatter'] list_filter = ('name', 'month', 'warehouse',) def apply_prove(self, obj): return format_html("<span>认证完成</span>") apply_prove.short_description = '入库次数' apply_prove.allow_tags = True def get_queryset(self, request): qs = super().get_queryset(request) if 'name' in request.GET and request.GET['name'] != 'none': # 条件查询 qs = qs.filter(name=request.GET['name']) if 'subjectMatter' in self.list_display: self.list_display.remove('subjectMatter') # qs = qs.values('month', 'warehouse').annotate(apply_prove=Count('id')).distinct() # self.list_display = ['name', 'month', 'warehouse', 'apply_prove'] if 'apply_prove' not in self.list_display: self.list_display.append('apply_prove') else: if 'subjectMatter' not in self.list_display: self.list_display.append('subjectMatter') if "apply_prove" in self.list_display: self.list_display.remove('apply_prove') return qs 代码中的qs = qs.filter(name=request.GET['name']),当前qs查询出来5个QuerySet实例,如何根据month和warehouse去重,并且将重复的条数定义为新字段添加在数据中,去重后结果不是字典,而是跟qs = qs.filter(name=request.GET['name'])结果类型一致

时间: 2024-01-21 21:03:07 浏览: 25
可以使用`values`和`annotate`方法来实现按照`month`和`warehouse`字段去重,并且将重复的条数定义为新字段添加在数据中。 可以将以下代码: ``` # qs = qs.filter(name=request.GET['name']).distinct() ``` 替换为以下代码: ``` qs = qs.filter(name=request.GET['name']).values('month', 'warehouse').annotate(apply_prove=Count('id')).distinct() ``` 这样就可以按照`month`和`warehouse`字段去重,并且将重复的条数定义为新字段`apply_prove`添加在数据中。注意要引入`Count`函数。
相关问题

class warehousePeopleBase(ModelAdmin): model = warehousePeople menu_label = '库房人员出入库信息' # ditch this to use verbose_name_plural from model menu_icon = 'site' # change as required list_display = ['name', 'yearMonth', 'month', 'warehouse', 'subjectMatter'] list_filter = ('name', 'yearMonth', 'month', 'warehouse',) wagtail怎么将右侧过滤器的yearMonth字段更改为可以任意的选择年份和月份?

你通过自定义`list_filter`来实现这个功能。具体步骤如下: 1. 定义一个自定义的Filter类,继承`django.contrib.admin.SimpleListFilter`类,重写`queryset`和`lookups`方法,来实现筛选功能。 ```python import datetime class YearMonthFilter(admin.SimpleListFilter): title = 'Year Month' parameter_name = 'year_month' def lookups(self, request, model_admin): # 获取所有可以选择的年月列表 year_month_list = [] for obj in model_admin.model.objects.all(): year_month = obj.yearMonth.strftime('%Y-%m') if year_month not in year_month_list: year_month_list.append(year_month) return [(ym, ym) for ym in year_month_list] def queryset(self, request, queryset): if self.value(): year_month = datetime.datetime.strptime(self.value(), '%Y-%m') return queryset.filter(yearMonth=year_month) ``` 2. 在`list_filter`中添加自定义的Filter类 ```python class warehousePeopleBase(ModelAdmin): model = warehousePeople menu_label = '库房人员出入库信息' # ditch this to use verbose_name_plural from model menu_icon = 'site' # change as required list_display = ['name', 'yearMonth', 'month', 'warehouse', 'subjectMatter'] list_filter = ('name', 'warehouse', YearMonthFilter) ``` 这样就可以在右侧过滤器中选择任意年份和月份进行筛选了。

我有一个渠道的点云文件为ditch.pcd,我想要提取渠道的中轴线,并获得渠道的断面切片。c++代码是什么

提取渠道的中轴线以及获得渠道的断面切片是点云处理中的经典问题。下面是一个简单的C++代码示例,使用PCL库实现了该功能。 ```c++ #include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/features/normal_3d.h> #include <pcl/filters/extract_indices.h> #include <pcl/filters/voxel_grid.h> #include <pcl/filters/passthrough.h> #include <pcl/sample_consensus/ransac.h> #include <pcl/sample_consensus/sac_model_line.h> #include <pcl/sample_consensus/sac_model_plane.h> #include <pcl/sample_consensus/sac_model_circle3d.h> #include <pcl/segmentation/sac_segmentation.h> #include <pcl/segmentation/extract_clusters.h> #include <pcl/visualization/pcl_visualizer.h> #include <iostream> #include <vector> int main (int argc, char** argv) { // Load input file pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); if (pcl::io::loadPCDFile<pcl::PointXYZ> ("ditch.pcd", *cloud) == -1) //* load the file { PCL_ERROR ("Couldn't read file ditch.pcd \n"); return (-1); } // Downsample input cloud pcl::VoxelGrid<pcl::PointXYZ> sor; sor.setInputCloud (cloud); sor.setLeafSize (0.1f, 0.1f, 0.1f); sor.filter (*cloud); // Extract points within a certain range pcl::PassThrough<pcl::PointXYZ> pass; pass.setInputCloud (cloud); pass.setFilterFieldName ("z"); pass.setFilterLimits (-1.0, 1.0); pass.filter (*cloud); // Estimate normals pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne; ne.setInputCloud (cloud); pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>); ne.setSearchMethod (tree); pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>); ne.setRadiusSearch (0.05); ne.compute (*cloud_normals); // Create the segmentation object for the planar model and set all the parameters pcl::SACSegmentationFromNormals<pcl::PointXYZ, pcl::Normal> seg; seg.setOptimizeCoefficients (true); seg.setModelType (pcl::SACMODEL_NORMAL_PLANE); seg.setNormalDistanceWeight (0.1); seg.setMethodType (pcl::SAC_RANSAC); seg.setMaxIterations (100); seg.setDistanceThreshold (0.03); seg.setInputCloud (cloud); seg.setInputNormals (cloud_normals); // Obtain the plane inliers and coefficients pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients); pcl::PointIndices::Ptr inliers (new pcl::PointIndices); seg.segment (*inliers, *coefficients); // Extract the planar inliers from the input cloud pcl::ExtractIndices<pcl::PointXYZ> extract; extract.setInputCloud (cloud); extract.setIndices (inliers); extract.setNegative (true); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>); extract.filter (*cloud_filtered); // Create the segmentation object for the line model and set all the parameters pcl::SACSegmentation<pcl::PointXYZ> seg_line; seg_line.setOptimizeCoefficients (true); seg_line.setModelType (pcl::SACMODEL_LINE); seg_line.setMethodType (pcl::SAC_RANSAC); seg_line.setMaxIterations (1000); seg_line.setDistanceThreshold (0.1); seg_line.setInputCloud (cloud_filtered); // Obtain the line inliers and coefficients pcl::ModelCoefficients::Ptr coefficients_line (new pcl::ModelCoefficients); pcl::PointIndices::Ptr inliers_line (new pcl::PointIndices); seg_line.segment (*inliers_line, *coefficients_line); // Extract the line inliers from the input cloud extract.setInputCloud (cloud_filtered); extract.setIndices (inliers_line); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_line (new pcl::PointCloud<pcl::PointXYZ>); extract.filter (*cloud_line); // Create a PCL visualizer pcl::visualization::PCLVisualizer viewer ("PCL Viewer"); // Add input cloud to viewer viewer.addPointCloud<pcl::PointXYZ> (cloud, "cloud"); // Add line fit to viewer viewer.addLine (*coefficients_line, 0, 255, 0, "line"); // Add plane fit to viewer viewer.addPlane (*coefficients, "plane"); // Display viewer while (!viewer.wasStopped ()) { viewer.spinOnce (); } return (0); } ``` 这段代码使用了点云库PCL(Point Cloud Library),实现了以下步骤: 1. 从文件中读取点云数据。 2. 对点云进行下采样,减少计算量。 3. 选取某个范围内的点云,去除无关的噪声。 4. 估计法向量,用于后续的拟合。 5. 使用RANSAC算法拟合平面模型,去除地面点云。 6. 使用RANSAC算法拟合直线模型,提取渠道的中轴线。 7. 可视化结果,包括原始点云、平面模型和直线模型。 你可以根据自己的需求进行修改和扩展。例如,添加断面切片的方法可以是: 1. 将中轴线上的点按照顺序连接起来,形成多边形。 2. 在多边形两侧分别选取一定数量的点云,按照垂线方向切割出一系列的断面。 3. 对每个断面进行分析和处理,例如计算面积、周长、高度等。

相关推荐

zip

最新推荐

recommend-type

基于关键词搜索结果的微博爬虫(下载即用).zip

基于关键词搜索结果的微博爬虫(下载即用).zip本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,当然也适合小白学习进阶。如果基础还行,可以在此代码基础上进行修改,以实现其他功能。 基于关键词搜索结果的微博爬虫(下载即用).zip本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,当然也适合小白学习进阶。如果基础还行,可以在此代码基础上进行修改,以实现其他功能。 基于关键词搜索结果的微博爬虫(下载即用).zip本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,当然也适合小白学习进阶。如果基础还行,可以在此代码基础上进行修改,以实现其他功能。 基于关键词搜索结果的微博爬虫(下载即用).zip本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,当然也适合小白学习进阶。如果基础还行,可以在此代码基础上进行修改
recommend-type

node-v4.4.1-headers.tar.xz

Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
recommend-type

J波模拟matlab代码.zip

1.版本:matlab2014/2019a/2021a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
recommend-type

Obsidian quickadd插件

Obsidian quickadd插件
recommend-type

Fraunhofer Versatile Video Encoder (VVenC) v0.1

这份文件是关于Fraunhofer Versatile Video Encoder (VVenC) v0.1版本的文档,由Fraunhofer Heinrich Hertz Institute (HHI)的视频编码与分析部门的Jens Brandenburg, Adam Wieckowski, Tobias Hinz, Benjamin Bross撰写
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】增量式PID的simulink仿真实现

# 2.1 Simulink仿真环境简介 Simulink是MATLAB中用于建模、仿真和分析动态系统的图形化环境。它提供了一个直观的用户界面,允许用户使用块和连接线来创建系统模型。Simulink模型由以下元素组成: - **子系统:**将复杂系统分解成更小的、可管理的模块。 - **块:**代表系统中的组件,如传感器、执行器和控制器。 - **连接线:**表示信号在块之间的流动。 Simulink仿真环境提供了广泛的块库,涵盖了各种工程学科,包括控制系统、电子和机械工程。它还支持用户自定义块的创建,以满足特定仿真需求。 # 2. Simulink仿真环境的搭建和建模 ### 2.
recommend-type

训练集和测试集的准确率都99%,但是预测效果不好

即使训练集和测试集的准确率都很高,但是在实际的预测中表现不佳,可能会有以下几个原因: 1. 数据质量问题:模型训练和测试的数据可能存在问题,比如数据标签错误、数据集采样不均衡、数据集中存在异常值等问题,这些问题可能会导致模型在实际预测中表现不佳。 2. 特征工程问题:模型的特征工程可能存在问题,导致模型无法很好地捕捉数据的特征,从而影响预测效果。 3. 模型选择问题:模型的选择可能不合适,比如选择的模型太简单,无法很好地拟合数据,或者选择的模型太复杂,导致过拟合等问题。 4. 超参数调整问题:模型的超参数可能没有调整到最佳状态,需要进行调整。 针对以上可能的原因,可以采取相应的措施进
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。