{"id":21972741,"url":"https://github.com/redatman/lens","last_synced_at":"2026-05-04T19:35:49.646Z","repository":{"id":86555323,"uuid":"333120209","full_name":"RedAtman/lens","owner":"RedAtman","description":"Lens —— Django通用增删改查组件，个人工作中封装的作为rest_ramework的另一个替代。 本质上为一个django项目的app，拷贝到django项目中后，加入settings.INSTALLED_APPS即可，开箱即用。","archived":false,"fork":false,"pushed_at":"2024-01-27T14:15:51.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T23:14:30.231Z","etag":null,"topics":["django","django-application","django-project","django1-11","django111","django2","django3","lens","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RedAtman.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-01-26T15:02:28.000Z","updated_at":"2024-01-27T14:15:56.000Z","dependencies_parsed_at":"2024-04-06T12:27:04.839Z","dependency_job_id":"c37beb02-5d3d-4ff6-91e5-5d4fc0034ffb","html_url":"https://github.com/RedAtman/lens","commit_stats":null,"previous_names":["redatman/lens"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RedAtman/lens","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedAtman%2Flens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedAtman%2Flens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedAtman%2Flens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedAtman%2Flens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RedAtman","download_url":"https://codeload.github.com/RedAtman/lens/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedAtman%2Flens/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32622242,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-application","django-project","django1-11","django111","django2","django3","lens","python","python3"],"created_at":"2024-11-29T15:20:43.034Z","updated_at":"2026-05-04T19:35:49.625Z","avatar_url":"https://github.com/RedAtman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lens —— Django通用增删改查组件\n\n个人工作中封装的作为rest_ramework的另一个替代。\n本质上为一个django项目的app，拷贝到django项目中后，加入settings.INSTALLED_APPS即可，开箱即用。\n\n## Feature\n- 通用增删改查API:\n    - 请求方法: 'GET', 'POST', 'PATCH', 'DELETE' 对应:查增改删。\n    - 自定义表字段显示控制。\n    - 全表字段模糊搜索。\n    - 指定表字段精确匹配搜索。\n    - 查询指定表字段最大、最小值。\n    - 分页控制。\n    - 自定义以指定字段进行排序。\n- 数据结构API:\n    - 查询指定app的所有model结构信息。\n    - 查询指定app指定model的所有字段结构信息。\n\n\n## Config\n1. 将整个组件作为app拷贝进已有django项目中。\n2. 注册: `settings.INSTALLED_APPS`中添加`lens.apps.LensConfig`。\n3. 配置: 在需要使用lens插件的app内新建`lens.py`文件，在`lens.py`文件中对model进行配置，示例如下:\n\nexample:\n    \n    # 3.1 引入lens、及lens封装的model配置基类ModelConfig\n    from lens import lens, ModelConfig\n    # 引入需要使用lens的models\n    from . import models\n\n    # 3.2 model配置类:继承lens配置基类ModelConfig\n    class FooConfig(ModelConfig):\n        \"\"\"数据表配置 其它表均可根据此来进行灵活配置 全部为可选项\"\"\"\n\n        # 指定Form类: 若需定制当前表的ModelForm\n        model_form_class = FooModelForm\n        # 指定允许显示的字段\n        list_display = []\n        # 指定禁止显示的字段\n        list_block = []\n        # 指定模糊搜索的字段范围\n        search_list = []\n        # 指定以某些字段排序\n        order_by = []\n        # 指定批量动作\n        # action_list = ['multi_delete']\n        # 是否分页\n        is_pagination = False\n        # 序列化层数: 目前仅支持0-1\n        depth = 1\n\n    # 3.3 将需要使用lens的model及写好的对应配置类注册到lens插件 即可完成配置\n    lens.register(models.Foo, FooConfig)\n        # 第一个参数是准备注册到lens中的model:必须项\n        # 第二个参数是上一步封装的配置类FooConfig:非必须项,若为空则使用基类ModelConfig的默认配置\n\n4. 添加到项目的url\n\nexample:\n\n    from lens import lens\n    urlpatterns = [\n        path('api/', lens.api), # 数据API\n        path('schema/', lens.schema),   # 数据结构API\n    ]\n\n\n## Usage\n### 请求方法\n'GET', 'POST', 'PATCH', 'DELETE' 对应:查增改删\n\n### API\n\napp信息及结构API: 默认版本v1\n\n    url: /schema/v1/apps\n    method: 'GET'\n    data: {}\n\n指定app指定model的表结构API: 默认版本v1\n\n    url: /schema/v1/\u003capp\u003e/\u003cmodel\u003e\n    method: 'GET'\n    data: {}\n\n指定app指定model数据API: 默认版本v1\n\n    url: /api/v1/\u003capp\u003e/\u003cmodel\u003e\n    method: 'GET', 'POST', 'PATCH', 'DELETE'\n    data: {}\n\n    # GET: 定义请求参数 data若为空字典则返回全表所有数据(分页方式)\n    data = {\n        # 'pk': 1,    # 获取指定主键的那条数据\n        # 'q': 1,   # 模糊搜索全表字段 或search_list中规定的字段范围\n        # 'max': 'id',  # 返回指定字段的最大值的那条数据\n        # 'min': 'id',  # 返回指定字段的最小值的那条数据\n        # '当前model的任意字段名': '任意值',   # 返回匹配任意字段名与任意值的那条数据\n    }\n\n    # POST: 在data中以dict定义每个字段的值 因为是增加数据因此不支持定义pk\n    data = {\n        'field_name': 'value',\n        ...\n    }\n\n    # PATCH: data中以dict方式定义要修改字段的值\n    data = {\n        'field_name': 'value',\n        ...\n    }\n    # DELETE: data中以dict方式定义要删除项的pk值 不可定义其它字段\n    data = {\n        'pk': 1,\n    }\n\n\n### 后端项目内直接调用lens通用API\n免除模拟Http请求访问接口\n\nexample:调用示例\n\n    # 1. 获取lens插件中注册的model对象\n    from . import models\n    foo = lens._registry.get(models.Foo)\n\n    # 2. 发送请求: response即为lens的API返回的数据\n    response = foo._api('get', data)\n        # 第一个参数是请求方法: 'GET', 'POST', 'PATCH', 'DELETE' 对应:查增改删\n        # 第二个参数是请求参数: 参考API部分\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredatman%2Flens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredatman%2Flens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredatman%2Flens/lists"}