{"id":38849,"date":"2025-05-21T10:36:06","date_gmt":"2025-05-21T02:36:06","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38849.html"},"modified":"2025-05-21T10:36:06","modified_gmt":"2025-05-21T02:36:06","slug":"%e4%b8%89%e3%80%81%e3%80%90%e6%95%b0%e6%8d%ae%e5%bb%ba%e6%a8%a1%e7%af%87%e3%80%91%ef%bc%9a%e7%94%a8-django-models-%e6%9e%84%e5%bb%ba%e6%b5%8b%e8%af%95%e5%b9%b3%e5%8f%b0%e6%a0%b8%e5%bf%83%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38849.html","title":{"rendered":"\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e"},"content":{"rendered":"<\/p>\n<h4>\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011&#xff1a;\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e<\/h4>\n<ul>\n<li>\n<ul>\n<li>\u524d\u8a00<\/li>\n<li>\n<ul>\n<li>\u6211\u4eec\u8981\u8bbe\u8ba1\u54ea\u4e9b\u6838\u5fc3\u6570\u636e&#xff1f;<\/li>\n<li>\u51c6\u5907\u5de5\u4f5c&#xff1a;\u521b\u5efa Django App<\/li>\n<li>\u5f00\u59cb\u8bbe\u8ba1\u6570\u636e\u6a21\u578b (Models)<\/li>\n<li>\n<ul>\n<li>1. \u901a\u7528\u57fa\u7840\u6a21\u578b (\u53ef\u9009\u4f46\u63a8\u8350)<\/li>\n<li>2. \u9879\u76ee\u6a21\u578b (Project)<\/li>\n<li>3. \u6a21\u5757\u6a21\u578b (Module)<\/li>\n<li>4. \u6d4b\u8bd5\u7528\u4f8b\u6a21\u578b (TestCase)<\/li>\n<\/ul>\n<\/li>\n<li>\u751f\u6210\u548c\u5e94\u7528\u6570\u636e\u5e93\u8fc1\u79fb<\/li>\n<li>\u5728 Django Admin \u4e2d\u67e5\u770b\u548c\u7ba1\u7406\u6570\u636e (\u53ef\u9009\u7684\u5feb\u901f\u9a8c\u8bc1)<\/li>\n<\/ul>\n<\/li>\n<li>\u603b\u7ed3<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u524d\u8a00<\/h3>\n<ul>\n<li>\u5728\u4e0a\u4e00\u7bc7&#xff0c;\u6211\u4eec\u6210\u529f\u642d\u5efa\u4e86 Django \u548c Vue3 \u7684\u5f00\u53d1\u73af\u5883&#xff0c;\u5c31\u50cf\u7ed9\u6211\u4eec\u7684\u201c\u5efa\u7b51\u5de5\u5730\u201d\u901a\u4e86\u6c34\u7535\u4e00\u6837\u3002\u4eca\u5929&#xff0c;\u6211\u4eec\u8981\u5f00\u59cb\u771f\u6b63\u7684\u201c\u5efa\u7b51\u8bbe\u8ba1\u201d\u4e86\u2014\u2014\u4e3a\u6211\u4eec\u7684\u6d4b\u8bd5\u5e73\u53f0\u8bbe\u8ba1\u6570\u636e\u6a21\u578b\u3002<\/li>\n<li>\u4ec0\u4e48\u662f\u6570\u636e\u6a21\u578b&#xff1f;\u7b80\u5355\u6765\u8bf4&#xff0c;\u6570\u636e\u6a21\u578b\u5c31\u662f\u6211\u4eec\u6d4b\u8bd5\u5e73\u53f0\u9700\u8981\u5b58\u50a8\u548c\u7ba1\u7406\u7684\u4fe1\u606f\u7684\u84dd\u56fe\u3002\u6bd4\u5982&#xff0c;\u4e00\u4e2a\u6d4b\u8bd5\u5e73\u53f0\u80af\u5b9a\u8981\u6709\u201c\u9879\u76ee\u201d\u3001\u201c\u6d4b\u8bd5\u7528\u4f8b\u201d\u3001\u201c\u6d4b\u8bd5\u62a5\u544a\u201d\u8fd9\u4e9b\u4e1c\u897f&#xff0c;\u6570\u636e\u6a21\u578b\u5c31\u662f\u7528\u6765\u7cbe\u786e\u5b9a\u4e49\u8fd9\u4e9b\u201c\u4e1c\u897f\u201d\u5305\u542b\u54ea\u4e9b\u4fe1\u606f&#xff08;\u6bd4\u5982\u9879\u76ee\u540d\u79f0\u3001\u7528\u4f8b\u6b65\u9aa4\u3001\u62a5\u544a\u7ed3\u679c\u7b49&#xff09;&#xff0c;\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u662f\u5982\u4f55\u5173\u8054\u7684\u3002<\/li>\n<li>\u5728 Django \u4e2d&#xff0c;\u6211\u4eec\u4f7f\u7528 Models \u6765\u5b9a\u4e49\u6570\u636e\u6a21\u578b\u3002\u4f60\u53ea\u9700\u8981\u7528 Python \u4ee3\u7801\u6765\u63cf\u8ff0\u4f60\u7684\u6570\u636e\u7ed3\u6784&#xff0c;Django \u4f1a\u81ea\u52a8\u5e2e\u4f60\u5904\u7406\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u7684\u590d\u6742\u7ec6\u8282&#xff08;\u6bd4\u5982\u521b\u5efa\u6570\u636e\u5e93\u8868&#xff09;\u3002<\/li>\n<\/ul>\n<h4>\u6211\u4eec\u8981\u8bbe\u8ba1\u54ea\u4e9b\u6838\u5fc3\u6570\u636e&#xff1f;<\/h4>\n<p>\u4e00\u4e2a\u57fa\u7840\u7684\u6d4b\u8bd5\u5e73\u53f0&#xff0c;\u901a\u5e38\u4f1a\u5305\u542b\u4ee5\u4e0b\u6838\u5fc3\u6570\u636e&#xff1a;<\/p>\n<li>\u9879\u76ee (Project)&#xff1a;\u7ba1\u7406\u4e0d\u540c\u7684\u6d4b\u8bd5\u9879\u76ee\u3002<\/li>\n<li>\u6a21\u5757 (Module)&#xff1a;\u9879\u76ee\u4e0b\u7684\u529f\u80fd\u6a21\u5757&#xff0c;\u7528\u4e8e\u7ec4\u7ec7\u6d4b\u8bd5\u7528\u4f8b\u3002<\/li>\n<li>\u6d4b\u8bd5\u7528\u4f8b (TestCase)&#xff1a;\u5177\u4f53\u7684\u6d4b\u8bd5\u70b9&#xff0c;\u5305\u542b\u4e00\u7cfb\u5217\u64cd\u4f5c\u6b65\u9aa4\u3002<\/li>\n<li>\u6d4b\u8bd5\u6b65\u9aa4 (TestStep)&#xff1a;\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u7684\u5355\u4e2a\u64cd\u4f5c&#xff0c;\u5982\u8bbf\u95eeURL\u3001\u70b9\u51fb\u6309\u94ae\u3001\u6821\u9a8c\u7ed3\u679c\u7b49&#xff08;\u4e3a\u4e86\u7b80\u5316\u5165\u95e8&#xff0c;\u6211\u4eec\u521d\u671f\u53ef\u4ee5\u5c06\u6b65\u9aa4\u5185\u7f6e\u4e8e\u7528\u4f8b\u4e2d&#xff0c;\u540e\u7eed\u53ef\u62c6\u5206&#xff09;\u3002<\/li>\n<li>\u6d4b\u8bd5\u914d\u7f6e (EnvironmentConfig \/ TestConfig)&#xff1a;\u7528\u4e8e\u5b58\u50a8\u4e0d\u540c\u6d4b\u8bd5\u73af\u5883\u7684\u914d\u7f6e\u4fe1\u606f&#xff0c;\u5982URL\u3001\u8d26\u6237\u7b49 (\u521d\u671f\u7b80\u5316&#xff0c;\u53ef\u653e\u5728\u9879\u76ee\u4e2d\u6216\u540e\u7eed\u6dfb\u52a0)\u3002<\/li>\n<li>\u6d4b\u8bd5\u6267\u884c\u8bb0\u5f55 (TestRun \/ ExecutionRecord)&#xff1a;\u8bb0\u5f55\u6bcf\u4e00\u6b21\u6d4b\u8bd5\u4efb\u52a1\u7684\u6267\u884c\u60c5\u51b5\u3002<\/li>\n<li>\u6d4b\u8bd5\u62a5\u544a (TestReport)&#xff1a;\u6c47\u603b\u5c55\u793a\u67d0\u6b21\u6d4b\u8bd5\u6267\u884c\u7684\u7ed3\u679c\u3002<\/li>\n<p>\u4e3a\u4e86\u8ba9\u5c0f\u767d\u66f4\u5bb9\u6613\u4e0a\u624b&#xff0c;\u6211\u4eec\u5148\u4ece\u6700\u6838\u5fc3\u7684 \u9879\u76ee (Project)\u3001\u6a21\u5757 (Module) \u548c \u6d4b\u8bd5\u7528\u4f8b (TestCase) \u5f00\u59cb\u8bbe\u8ba1&#xff0c;\u5e76\u9010\u6b65\u5b8c\u5584\u3002<\/p>\n<h4>\u51c6\u5907\u5de5\u4f5c&#xff1a;\u521b\u5efa Django App<\/h4>\n<p>\u5728 Django \u4e2d&#xff0c;\u9879\u76ee\u901a\u5e38\u7531\u591a\u4e2a App \u7ec4\u6210&#xff0c;\u6bcf\u4e2a App \u8d1f\u8d23\u4e00\u90e8\u5206\u72ec\u7acb\u7684\u529f\u80fd\u3002\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a api \u7684 App \u6765\u5b58\u653e\u6211\u4eec\u6d4b\u8bd5\u5e73\u53f0\u540e\u7aef\u7684\u6838\u5fc3\u903b\u8f91&#xff0c;\u5305\u62ec\u6570\u636e\u6a21\u578b\u3002<\/p>\n<li>\n<p>\u6fc0\u6d3b Python \u865a\u62df\u73af\u5883&#xff1a;<\/p>\n<ul>\n<li>\u6253\u5f00Terminal&#xff1a;\n<ul>\n<li>Windows&#xff1a;venv\\\\Scripts\\\\activate<\/li>\n<li>macOS\/Linux: source venv\/bin\/activate<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u521b\u5efa Django \u9879\u76ee&#xff1a; \u867d\u7136\u6211\u4eec\u4e4b\u524d\u5b89\u88c5\u4e86 Django&#xff0c;\u4f46\u8fd8\u6ca1\u6709\u6b63\u5f0f\u521b\u5efa\u4e00\u4e2a Django \u9879\u76ee\u3002\u4e00\u4e2a Django \u9879\u76ee\u662f\u914d\u7f6e\u548c\u591a\u4e2a\u5e94\u7528\u7684\u96c6\u5408\u3002 \u5728 test-platform \u76ee\u5f55\u4e0b (\u786e\u4fdd (venv) \u5df2\u6fc0\u6d3b)&#xff0c;\u6267\u884c&#xff1a;<\/p>\n<p> django-admin startproject backend <span class=\"token builtin class-name\">.<\/span><\/p>\n<p>\u6ce8\u610f\u547d\u4ee4\u6700\u540e\u7684\u90a3\u4e2a\u70b9 .&#xff0c;\u5b83\u8868\u793a\u5728\u5f53\u524d\u76ee\u5f55 (test-platform) \u4e0b\u521b\u5efa Django \u9879\u76ee\u6587\u4ef6&#xff0c;\u800c\u4e0d\u662f\u518d\u65b0\u5efa\u4e00\u4e2a\u540c\u540d\u5b50\u76ee\u5f55\u3002<\/p>\n<p>\u6267\u884c\u540e&#xff0c;\u4f60\u7684 test-platform \u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023559-682d3c0f68663.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u8fd9\u91cc\u7684 backend \u6587\u4ef6\u5939\u662f Django \u9879\u76ee\u7684\u914d\u7f6e\u76ee\u5f55&#xff0c;settings.py \u662f\u9879\u76ee\u914d\u7f6e\u6587\u4ef6&#xff0c;\u800c manage.py \u662fDjango \u9879\u76ee\u7ba1\u7406\u811a\u672c\u5de5\u5177&#xff0c;\u6211\u4eec\u5c06\u9891\u7e41\u4f7f\u7528\u5b83\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa Django App&#xff1a; \u73b0\u5728&#xff0c;\u4f7f\u7528 manage.py \u6765\u521b\u5efa\u6211\u4eec\u7684 api \u5e94\u7528\u3002\u786e\u4fdd\u4f60\u5728 test-platform \u6839\u76ee\u5f55\u4e0b\u3002<\/p>\n<p> python manage.py startapp api<\/p>\n<p>\u6267\u884c\u540e&#xff0c;test-platform \u76ee\u5f55\u4e0b\u4f1a\u65b0\u589e\u4e00\u4e2a api \u6587\u4ef6\u5939&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023559-682d3c0f818ba.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u6211\u4eec\u5c06\u5728models.py\u8fd9\u91cc\u5b9a\u4e49\u6570\u636e\u6a21\u578b\u3002<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u518c App&#xff1a; \u521b\u5efa\u4e86 App \u4e4b\u540e&#xff0c;\u8fd8\u9700\u8981\u544a\u8bc9 Django \u9879\u76ee\u5b83\u7684\u5b58\u5728\u3002\u6253\u5f00 test-platform\/backend\/settings.py \u6587\u4ef6&#xff0c;\u627e\u5230 INSTALLED_APPS \u5217\u8868&#xff0c;\u5728\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u6211\u4eec\u7684 api \u5e94\u7528&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023559-682d3c0f99707.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p> <span class=\"token comment\"># test-platform\/backend\/settings.py<\/span><\/p>\n<p>INSTALLED_APPS <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n    <span class=\"token string\">&#039;django.contrib.admin&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#039;django.contrib.auth&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#039;django.contrib.contenttypes&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#039;django.contrib.sessions&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#039;django.contrib.messages&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#039;django.contrib.staticfiles&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#039;rest_framework&#039;<\/span><span class=\"token punctuation\">,<\/span>  <span class=\"token comment\"># \u6211\u4eec\u4e4b\u524d\u5b89\u88c5\u4e86DRF&#xff0c;\u5728\u8fd9\u91cc\u4e5f\u6ce8\u518c\u4e0a<\/span><br \/>\n    <span class=\"token string\">&#039;api&#039;<\/span><span class=\"token punctuation\">,<\/span>             <span class=\"token comment\"># \u6dfb\u52a0\u6211\u4eec\u65b0\u5efa\u7684 app<\/span><br \/>\n<span class=\"token punctuation\">]<\/span><\/p>\n<p>\u8bb0\u5f97\u4fdd\u5b58\u6587\u4ef6\u3002<\/p>\n<\/li>\n<h4>\u5f00\u59cb\u8bbe\u8ba1\u6570\u636e\u6a21\u578b (Models)<\/h4>\n<p>\u73b0\u5728&#xff0c;\u6253\u5f00 test-platform\/api\/models.py \u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u521d\u59cb\u53ea\u6709\u4e00\u4e9b\u6ce8\u91ca\u3002\u6211\u4eec\u5c06\u5728\u8fd9\u91cc\u7528 Python \u7c7b\u6765\u5b9a\u4e49\u6211\u4eec\u7684\u6570\u636e\u6a21\u578b\u3002<\/p>\n<h5>1. \u901a\u7528\u57fa\u7840\u6a21\u578b (\u53ef\u9009\u4f46\u63a8\u8350)<\/h5>\n<p>\u4e3a\u4e86\u4ee3\u7801\u590d\u7528\u548c\u7edf\u4e00\u7ba1\u7406\u521b\u5efa\u65f6\u95f4\u3001\u66f4\u65b0\u65f6\u95f4\u7b49\u901a\u7528\u5b57\u6bb5&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5148\u5b9a\u4e49\u4e00\u4e2a\u57fa\u7840\u6a21\u578b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023559-682d3c0fed99c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\"># test-platform\/api\/models.py<\/span><br \/>\n<span class=\"token keyword\">from<\/span> django<span class=\"token punctuation\">.<\/span>db <span class=\"token keyword\">import<\/span> models<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">BaseModel<\/span><span class=\"token punctuation\">(<\/span>models<span class=\"token punctuation\">.<\/span>Model<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n    \u516c\u5171\u6a21\u578b,\u53ef\u6dfb\u52a0\u521b\u5efa\u65f6\u95f4\/\u66f4\u65b0\u65f6\u95f4\/\u903b\u8f91\u5220\u9664\u7b49\u901a\u7528\u5b57\u6bb5<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    name <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>CharField<span class=\"token punctuation\">(<\/span>max_length<span class=\"token operator\">&#061;<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">,<\/span> unique<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u540d\u79f0&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    description <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>TextField<span class=\"token punctuation\">(<\/span>null<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> blank<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u63cf\u8ff0&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    create_time <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>DateTimeField<span class=\"token punctuation\">(<\/span>auto_now_add<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u521b\u5efa\u65f6\u95f4&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    update_time <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>DateTimeField<span class=\"token punctuation\">(<\/span>auto_now<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u66f4\u65b0\u65f6\u95f4&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Meta<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        abstract <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">True<\/span>  <span class=\"token comment\"># \u8bbe\u7f6e\u4e3a\u62bd\u8c61\u57fa\u7c7b&#xff0c;\u4e0d\u4f1a\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u8868<\/span><br \/>\n        ordering <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;-create_time&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token comment\"># \u9ed8\u8ba4\u6309\u521b\u5efa\u65f6\u95f4\u5012\u5e8f<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__str__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> self<span class=\"token punctuation\">.<\/span>name<\/p>\n<ul>\n<li>models.Model: \u6240\u6709 Django \u6a21\u578b\u90fd\u7ee7\u627f\u81ea\u5b83\u3002<\/li>\n<li>name &#061; models.CharField(&#8230;): \u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u7c7b\u578b\u5b57\u6bb5&#xff0c;max_length \u662f\u6700\u5927\u957f\u5ea6&#xff0c;unique&#061;True \u8868\u793a\u540d\u79f0\u4e0d\u80fd\u91cd\u590d&#xff0c;verbose_name \u662f\u5728 Django admin \u540e\u53f0\u663e\u793a\u7684\u53cb\u597d\u540d\u79f0\u3002<\/li>\n<li>description &#061; models.TextField(&#8230;): \u5b9a\u4e49\u4e00\u4e2a\u6587\u672c\u7c7b\u578b\u5b57\u6bb5&#xff0c;null&#061;True \u8868\u793a\u6570\u636e\u5e93\u4e2d\u53ef\u4ee5\u4e3a\u7a7a&#xff0c;blank&#061;True \u8868\u793a\u5728\u8868\u5355\u4e2d\u53ef\u4ee5\u4e0d\u586b\u3002<\/li>\n<li>create_time &#061; models.DateTimeField(auto_now_add&#061;True, &#8230;): \u65e5\u671f\u65f6\u95f4\u5b57\u6bb5&#xff0c;auto_now_add&#061;True \u8868\u793a\u5728\u5bf9\u8c61\u7b2c\u4e00\u6b21\u521b\u5efa\u65f6\u81ea\u52a8\u8bbe\u7f6e\u4e3a\u5f53\u524d\u65f6\u95f4\u3002<\/li>\n<li>update_time &#061; models.DateTimeField(auto_now&#061;True, &#8230;): \u65e5\u671f\u65f6\u95f4\u5b57\u6bb5&#xff0c;auto_now&#061;True \u8868\u793a\u5728\u5bf9\u8c61\u6bcf\u6b21\u4fdd\u5b58\u65f6\u81ea\u52a8\u66f4\u65b0\u4e3a\u5f53\u524d\u65f6\u95f4\u3002<\/li>\n<li>class Meta: \u7528\u4e8e\u5b9a\u4e49\u6a21\u578b\u7684\u5143\u6570\u636e\u3002\n<ul>\n<li>abstract &#061; True: \u8868\u793a BaseModel \u662f\u4e00\u4e2a\u62bd\u8c61\u57fa\u7c7b\u3002\u5b83\u672c\u8eab\u4e0d\u4f1a\u88ab\u521b\u5efa\u6210\u6570\u636e\u5e93\u8868&#xff0c;\u800c\u662f\u7528\u6765\u88ab\u5176\u4ed6\u6a21\u578b\u7ee7\u627f&#xff0c;\u4ece\u800c\u5171\u4eab\u8fd9\u4e9b\u901a\u7528\u5b57\u6bb5\u3002<\/li>\n<li>ordering &#061; [&#039;-create_time&#039;]: \u6307\u5b9a\u67e5\u8be2\u6b64\u6a21\u578b\u7684\u5bf9\u8c61\u65f6&#xff0c;\u9ed8\u8ba4\u6309\u521b\u5efa\u65f6\u95f4\u964d\u5e8f\u6392\u5217 (\u6700\u65b0\u7684\u5728\u524d\u9762)\u3002<\/li>\n<\/ul>\n<\/li>\n<li>__str__(self): \u5b9a\u4e49\u5f53\u6253\u5370\u6a21\u578b\u5b9e\u4f8b\u65f6&#xff0c;\u8fd4\u56de\u7684\u5185\u5bb9\u3002\u8fd9\u91cc\u6211\u4eec\u8fd4\u56de\u5176\u540d\u79f0\u3002<\/li>\n<\/ul>\n<h5>2. \u9879\u76ee\u6a21\u578b (Project)<\/h5>\n<p>\u4e00\u4e2a\u6d4b\u8bd5\u9879\u76ee\u662f\u6211\u4eec\u7ec4\u7ec7\u6d4b\u8bd5\u7684\u9876\u5c42\u5355\u4f4d\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023600-682d3c103cf3b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\"># test-platform\/api\/models.py<\/span><br \/>\n<span class=\"token comment\"># (\u7ee7\u7eed\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u6dfb\u52a0&#xff0c;BaseModel\u5b9a\u4e49\u4e4b\u540e)<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Project<\/span><span class=\"token punctuation\">(<\/span>BaseModel<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token comment\"># \u7ee7\u627f\u81ea\u6211\u4eec\u5b9a\u4e49\u7684 BaseModel<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n    \u9879\u76ee\u8868<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># name \u548c description \u5b57\u6bb5\u5df2\u4ece BaseModel \u7ee7\u627f<\/span><br \/>\n    <span class=\"token comment\"># create_time \u548c update_time \u5b57\u6bb5\u5df2\u4ece BaseModel \u7ee7\u627f<\/span><\/p>\n<p>    <span class=\"token comment\"># \u53ef\u4ee5\u6dfb\u52a0\u9879\u76ee\u7279\u6709\u7684\u5b57\u6bb5&#xff0c;\u4f8b\u5982&#xff1a;<\/span><br \/>\n    <span class=\"token comment\">#\u8d1f\u8d23\u4eba<\/span><br \/>\n    owner <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>CharField<span class=\"token punctuation\">(<\/span>max_length<span class=\"token operator\">&#061;<\/span><span class=\"token number\">50<\/span><span class=\"token punctuation\">,<\/span> null<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> blank<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u8d1f\u8d23\u4eba&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\">#\u9879\u76ee\u72b6\u6001&#xff1a;0-\u89c4\u5212\u4e2d&#xff0c;1-\u8fdb\u884c\u4e2d&#xff0c;2-\u5df2\u5b8c\u6210&#xff0c;3-\u6401\u7f6e<\/span><br \/>\n    status <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>PositiveSmallIntegerField<span class=\"token punctuation\">(<\/span>default<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u9879\u76ee\u72b6\u6001&#034;<\/span><span class=\"token punctuation\">,<\/span> help_text<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;0:\u89c4\u5212\u4e2d, 1:\u8fdb\u884c\u4e2d, 2:\u5df2\u5b8c\u6210, 3:\u6401\u7f6e&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Meta<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        verbose_name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u9879\u76ee&#034;<\/span> <span class=\"token comment\"># \u5355\u6570\u5f62\u5f0f\u7684\u53cb\u597d\u540d\u79f0<\/span><br \/>\n        verbose_name_plural <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u9879\u76ee\u5217\u8868&#034;<\/span> <span class=\"token comment\"># \u590d\u6570\u5f62\u5f0f\u7684\u53cb\u597d\u540d\u79f0<\/span><br \/>\n        ordering <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;-create_time&#039;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token comment\"># \u4e5f\u53ef\u4ee5\u5728\u8fd9\u91cc\u8986\u76d6\u6216\u6dfb\u52a0\u6392\u5e8f\u89c4\u5219<\/span><\/p>\n<p>    <span class=\"token comment\"># __str__ \u65b9\u6cd5\u5df2\u4ece BaseModel \u7ee7\u627f<\/span><\/p>\n<p>\u6211\u4eec\u8ba9 Project \u6a21\u578b\u7ee7\u627f\u4e86 BaseModel&#xff0c;\u6240\u4ee5\u5b83\u81ea\u52a8\u62e5\u6709\u4e86 name, description, create_time, update_time \u5b57\u6bb5\u3002\u6211\u4eec\u53c8\u6dfb\u52a0\u4e86 owner \u548c status \u4e24\u4e2a\u9879\u76ee\u7279\u6709\u7684\u5b57\u6bb5\u3002<\/p>\n<h5>3. \u6a21\u5757\u6a21\u578b (Module)<\/h5>\n<p>\u6a21\u5757\u901a\u5e38\u5c5e\u4e8e\u67d0\u4e2a\u9879\u76ee&#xff0c;\u7528\u4e8e\u5bf9\u6d4b\u8bd5\u7528\u4f8b\u8fdb\u884c\u5206\u7c7b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023600-682d3c108d7c4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\"># test-platform\/api\/models.py<\/span><br \/>\n<span class=\"token comment\"># (\u7ee7\u7eed\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u6dfb\u52a0)<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Module<\/span><span class=\"token punctuation\">(<\/span>BaseModel<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n    \u6a21\u5757\u8868<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># name \u548c description \u5b57\u6bb5\u5df2\u4ece BaseModel \u7ee7\u627f<\/span><br \/>\n    <span class=\"token comment\"># create_time \u548c update_time \u5b57\u6bb5\u5df2\u4ece BaseModel \u7ee7\u627f<\/span><\/p>\n<p>    project <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>ForeignKey<span class=\"token punctuation\">(<\/span>Project<span class=\"token punctuation\">,<\/span> on_delete<span class=\"token operator\">&#061;<\/span>models<span class=\"token punctuation\">.<\/span>CASCADE<span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u6240\u5c5e\u9879\u76ee&#034;<\/span><span class=\"token punctuation\">,<\/span> related_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;modules&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># &#039;Project&#039;&#xff1a;\u5173\u8054\u5230 Project \u6a21\u578b\u3002<\/span><br \/>\n    <span class=\"token comment\"># on_delete&#061;models.CASCADE&#xff1a;\u7ea7\u8054\u5220\u9664\u3002\u5f53\u5176\u6240\u5c5e\u7684 Project \u88ab\u5220\u9664\u65f6&#xff0c;\u8fd9\u4e2a Module \u4e5f\u4f1a\u88ab\u81ea\u52a8\u5220\u9664\u3002<\/span><br \/>\n    <span class=\"token comment\"># verbose_name&#xff1a;\u53cb\u597d\u540d\u79f0\u3002<\/span><br \/>\n    <span class=\"token comment\"># related_name&#061;&#034;modules&#034;&#xff1a;\u8fd9\u5141\u8bb8\u6211\u4eec\u4ece\u4e00\u4e2a Project \u5b9e\u4f8b\u901a\u8fc7 &#096;project_instance.modules.all()&#096; \u6765\u83b7\u53d6\u5176\u4e0b\u6240\u6709\u7684 Module \u5b9e\u4f8b\u3002<\/span><\/p>\n<p>    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Meta<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        verbose_name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u6a21\u5757&#034;<\/span><br \/>\n        verbose_name_plural <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u6a21\u5757\u5217\u8868&#034;<\/span><br \/>\n        <span class=\"token comment\"># \u540c\u4e00\u4e2a\u9879\u76ee\u4e0b\u7684\u6a21\u5757\u540d\u4e0d\u80fd\u91cd\u590d<\/span><br \/>\n        unique_together <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;project&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;name&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># project \u548c name \u7ec4\u5408\u8d77\u6765\u5fc5\u987b\u552f\u4e00<\/span><\/p>\n<p>    <span class=\"token comment\"># __str__ \u65b9\u6cd5\u5df2\u4ece BaseModel \u7ee7\u627f&#xff0c;\u53ef\u4ee5\u8003\u8651\u91cd\u5199\u4ee5\u5305\u542b\u9879\u76ee\u4fe1\u606f<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__str__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>project<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> &#8211; <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><\/p>\n<p>\u8fd9\u91cc\u6700\u91cd\u8981\u7684\u662f project &#061; models.ForeignKey(Project, &#8230;)&#xff0c;\u5b83\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5916\u952e\u5173\u7cfb\u3002\u8fd9\u610f\u5473\u7740\u4e00\u4e2a\u6a21\u5757\u5fc5\u987b\u5c5e\u4e8e\u4e00\u4e2a\u9879\u76ee\u3002<\/p>\n<h5>4. \u6d4b\u8bd5\u7528\u4f8b\u6a21\u578b (TestCase)<\/h5>\n<p>\u6d4b\u8bd5\u7528\u4f8b\u662f\u6d4b\u8bd5\u7684\u6838\u5fc3&#xff0c;\u5b83\u5c5e\u4e8e\u67d0\u4e2a\u6a21\u5757\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023600-682d3c10e5a75.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\"># test-platform\/api\/models.py<\/span><br \/>\n<span class=\"token comment\"># (\u7ee7\u7eed\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u6dfb\u52a0)<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">TestCase<\/span><span class=\"token punctuation\">(<\/span>BaseModel<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n    \u6d4b\u8bd5\u7528\u4f8b\u8868<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># name \u548c description \u5b57\u6bb5\u5df2\u4ece BaseModel \u7ee7\u627f<\/span><br \/>\n    <span class=\"token comment\"># create_time \u548c update_time \u5b57\u6bb5\u5df2\u4ece BaseModel \u7ee7\u627f<\/span><\/p>\n<p>    module <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>ForeignKey<span class=\"token punctuation\">(<\/span>Module<span class=\"token punctuation\">,<\/span> on_delete<span class=\"token operator\">&#061;<\/span>models<span class=\"token punctuation\">.<\/span>CASCADE<span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u6240\u5c5e\u6a21\u5757&#034;<\/span><span class=\"token punctuation\">,<\/span> related_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;testcases&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u7528\u4f8b\u7ea7\u522b: P0, P1, P2, P3<\/span><br \/>\n    priority_choices <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;P0&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;P0 &#8211; \u6700\u9ad8&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;P1&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;P1 &#8211; \u9ad8&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;P2&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;P2 &#8211; \u4e2d&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;P3&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;P3 &#8211; \u4f4e&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">]<\/span><br \/>\n    priority <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>CharField<span class=\"token punctuation\">(<\/span>max_length<span class=\"token operator\">&#061;<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> choices<span class=\"token operator\">&#061;<\/span>priority_choices<span class=\"token punctuation\">,<\/span> default<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;P1&#039;<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u4f18\u5148\u7ea7&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u524d\u7f6e\u6761\u4ef6<\/span><br \/>\n    precondition <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>TextField<span class=\"token punctuation\">(<\/span>null<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> blank<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u524d\u7f6e\u6761\u4ef6&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u6d4b\u8bd5\u6b65\u9aa4 (\u521d\u671f\u7b80\u5316&#xff0c;\u76f4\u63a5\u5b58\u5728\u7528\u4f8b\u4e2d&#xff0c;\u53ef\u4ee5\u7528JSON\u683c\u5f0f\u6216\u7279\u5b9a\u6587\u672c\u683c\u5f0f)<\/span><br \/>\n    <span class=\"token comment\"># \u66f4\u597d\u7684\u505a\u6cd5\u662f\u5355\u72ec\u521b\u5efa\u4e00\u4e2a TestStep \u6a21\u578b&#xff0c;\u5e76\u4e0e TestCase \u5efa\u7acb\u4e00\u5bf9\u591a\u5173\u7cfb<\/span><br \/>\n    steps_text <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>TextField<span class=\"token punctuation\">(<\/span>verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u6d4b\u8bd5\u6b65\u9aa4 (\u6587\u672c\u63cf\u8ff0)&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u9884\u671f\u7ed3\u679c<\/span><br \/>\n    expected_result <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>TextField<span class=\"token punctuation\">(<\/span>verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u9884\u671f\u7ed3\u679c&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u7528\u4f8b\u7c7b\u578b&#xff1a;\u4f8b\u5982 \u529f\u80fd\u6d4b\u8bd5&#xff0c;\u63a5\u53e3\u6d4b\u8bd5&#xff0c;UI\u6d4b\u8bd5 (\u521d\u671f\u53ef\u4ee5\u7b80\u5355\u70b9&#xff0c;\u540e\u7eed\u6269\u5c55)<\/span><br \/>\n    case_type_choices <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;functional&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u529f\u80fd\u6d4b\u8bd5&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;api&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u63a5\u53e3\u6d4b\u8bd5&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;ui&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;UI\u6d4b\u8bd5&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">]<\/span><br \/>\n    case_type <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>CharField<span class=\"token punctuation\">(<\/span>max_length<span class=\"token operator\">&#061;<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">,<\/span> choices<span class=\"token operator\">&#061;<\/span>case_type_choices<span class=\"token punctuation\">,<\/span> default<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;functional&#039;<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u7528\u4f8b\u7c7b\u578b&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u7ef4\u62a4\u4eba<\/span><br \/>\n    maintainer <span class=\"token operator\">&#061;<\/span> models<span class=\"token punctuation\">.<\/span>CharField<span class=\"token punctuation\">(<\/span>max_length<span class=\"token operator\">&#061;<\/span><span class=\"token number\">50<\/span><span class=\"token punctuation\">,<\/span> null<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> blank<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span> verbose_name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u7ef4\u62a4\u4eba&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Meta<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        verbose_name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u6d4b\u8bd5\u7528\u4f8b&#034;<\/span><br \/>\n        verbose_name_plural <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u6d4b\u8bd5\u7528\u4f8b\u5217\u8868&#034;<\/span><br \/>\n        <span class=\"token comment\"># \u540c\u4e00\u4e2a\u6a21\u5757\u4e0b\u7684\u7528\u4f8b\u540d\u4e0d\u80fd\u91cd\u590d<\/span><br \/>\n        unique_together <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;module&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;name&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># __str__ \u65b9\u6cd5\u5df2\u4ece BaseModel \u7ee7\u627f&#xff0c;\u53ef\u4ee5\u8003\u8651\u91cd\u5199<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__str__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>module<span class=\"token punctuation\">.<\/span>project<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> &#8211; <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>module<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> &#8211; <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><\/p>\n<ul>\n<li>priority &#061; models.CharField(&#8230;, choices&#061;priority_choices, &#8230;): choices \u53c2\u6570\u5141\u8bb8\u4f60\u5b9a\u4e49\u4e00\u4e2a\u4e0b\u62c9\u9009\u62e9\u5217\u8868\u3002<\/li>\n<li>steps_text: \u6211\u4eec\u6682\u65f6\u7528\u4e00\u4e2a\u5927\u7684\u6587\u672c\u5b57\u6bb5\u6765\u5b58\u50a8\u6d4b\u8bd5\u6b65\u9aa4&#xff0c;\u8fd9\u5bf9\u4e8e\u5165\u95e8\u6bd4\u8f83\u7b80\u5355\u3002\u5728\u66f4\u590d\u6742\u7684\u7cfb\u7edf\u4e2d&#xff0c;\u4f60\u53ef\u80fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u5355\u72ec\u7684 TestStep \u6a21\u578b&#xff0c;\u5e76\u8ba9\u4e00\u4e2a TestCase \u5173\u8054\u591a\u4e2a TestStep\u3002<\/li>\n<\/ul>\n<h4>\u751f\u6210\u548c\u5e94\u7528\u6570\u636e\u5e93\u8fc1\u79fb<\/h4>\n<p>\u6a21\u578b\u5b9a\u4e49\u597d\u4e86&#xff0c;\u4f46\u6570\u636e\u5e93\u8fd8\u4e0d\u77e5\u9053\u8fd9\u4e9b\u3002\u6211\u4eec\u9700\u8981\u544a\u8bc9 Django \u6839\u636e\u6211\u4eec\u7684\u6a21\u578b\u5b9a\u4e49\u6765\u521b\u5efa\u6216\u4fee\u6539\u6570\u636e\u5e93\u8868\u7ed3\u6784\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u53eb\u505a\u6570\u636e\u5e93\u8fc1\u79fb (Migrations)\u3002<\/p>\n<li>\n<p>\u751f\u6210\u8fc1\u79fb\u6587\u4ef6&#xff1a; \u5728\u7ec8\u7aef\u4e2d (\u786e\u4fdd\u5728 test-platform \u76ee\u5f55\u4e0b&#xff0c;\u5e76\u4e14 (venv) \u5df2\u6fc0\u6d3b)&#xff0c;\u8fd0\u884c&#xff1a;<\/p>\n<p> python manage.py makemigrations api<\/p>\n<p>\u4f60\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023601-682d3c118626f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5982\u679c\u4f60\u7684\u6a21\u578b\u5b9a\u4e49\u6ca1\u6709\u8bed\u6cd5\u9519\u8bef&#xff0c;Django \u4f1a\u68c0\u67e5 api\/models.py \u6587\u4ef6\u7684\u6539\u52a8&#xff0c;\u5e76\u5728 api\/migrations\/ \u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u8fc1\u79fb\u6587\u4ef6&#xff0c; 0001_initial.py\u3002\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u4e86\u5982\u4f55\u521b\u5efa Project, Module, TestCase \u8868\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023601-682d3c1193b90.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<li>\n<p>\u5e94\u7528\u8fc1\u79fb\u5230\u6570\u636e\u5e93&#xff1a; \u8fc1\u79fb\u6587\u4ef6\u751f\u6210\u540e&#xff0c;\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5c06\u8fd9\u4e9b\u66f4\u6539\u5e94\u7528\u5230\u6570\u636e\u5e93&#xff08;Django \u9ed8\u8ba4\u4f7f\u7528 SQLite \u6587\u4ef6\u6570\u636e\u5e93&#xff0c;\u5b83\u4f1a\u5728\u4f60\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a db.sqlite3 \u6587\u4ef6&#xff09;&#xff1a;<\/p>\n<p> python manage.py migrate<\/p>\n<p>\u4f60\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa&#xff0c;\u8868\u793a\u4f60\u7684\u6570\u636e\u5e93\u8868\u5df2\u7ecf\u6839\u636e\u6a21\u578b\u6210\u529f\u521b\u5efa\u4e86&#xff01;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023602-682d3c12051c7.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023602-682d3c121c84e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<p>\u9a8c\u8bc1\u6570\u636e\u5e93\u8868 (\u53ef\u9009&#xff0c;\u4f46\u63a8\u8350)<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 SQLite \u7684\u6d4f\u89c8\u5668\u5de5\u5177&#xff08;\u6bd4\u5982 DB Browser for SQLite&#xff09;\u6253\u5f00\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u7684 db.sqlite3 \u6587\u4ef6&#xff0c;\u67e5\u770b\u662f\u5426\u751f\u6210\u4e86\u8868&#xff0c;\u4ee5\u53ca\u5b83\u4eec\u7684\u5217\u7ed3\u6784\u662f\u5426\u7b26\u5408\u5b9a\u4e49\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023602-682d3c122e903.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>\u5728 Django Admin \u4e2d\u67e5\u770b\u548c\u7ba1\u7406\u6570\u636e (\u53ef\u9009\u7684\u5feb\u901f\u9a8c\u8bc1)<\/h4>\n<p>Django \u81ea\u5e26\u4e00\u4e2a\u5f3a\u5927\u7684\u540e\u53f0\u7ba1\u7406\u754c\u9762 (Django Admin)&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u6765\u5feb\u901f\u67e5\u770b\u548c\u6dfb\u52a0\u6570\u636e&#xff0c;\u9a8c\u8bc1\u6a21\u578b\u662f\u5426\u5de5\u4f5c\u6b63\u5e38\u3002<\/p>\n<li>\n<p>\u521b\u5efa\u8d85\u7ea7\u7528\u6237&#xff1a;<\/p>\n<p>\u4f60\u9700\u8981\u4e00\u4e2a\u7ba1\u7406\u5458\u8d26\u53f7\u6765\u767b\u5f55 Django Admin\u3002\u5728\u7ec8\u7aef\u8fd0\u884c&#xff1a;<\/p>\n<p> python manage.py createsuperuser<\/p>\n<p>\u6309\u7167\u63d0\u793a\u8f93\u5165\u7528\u6237\u540d\u3001\u90ae\u7bb1&#xff08;\u53ef\u4ee5\u968f\u4fbf\u586b\u4e00\u4e2a\u683c\u5f0f\u6b63\u786e\u7684&#xff09;\u3001\u5bc6\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023602-682d3c1279d5b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<li>\n<p>\u6ce8\u518c\u6a21\u578b\u5230 Admin&#xff1a; \u6253\u5f00 test-platform\/api\/admin.py \u6587\u4ef6&#xff0c;\u5c06\u6211\u4eec\u7684\u6a21\u578b\u6ce8\u518c\u8fdb\u53bb&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023602-682d3c1288c1f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p> <span class=\"token comment\"># test-platform\/api\/admin.py<\/span><br \/>\n<span class=\"token keyword\">from<\/span> django<span class=\"token punctuation\">.<\/span>contrib <span class=\"token keyword\">import<\/span> admin<br \/>\n<span class=\"token keyword\">from<\/span> <span class=\"token punctuation\">.<\/span>models <span class=\"token keyword\">import<\/span> Project<span class=\"token punctuation\">,<\/span> Module<span class=\"token punctuation\">,<\/span> TestCase <span class=\"token comment\"># \u5bfc\u5165\u4f60\u7684\u6a21\u578b<\/span><\/p>\n<p><span class=\"token comment\"># \u6ce8\u518c\u6a21\u578b\u5230 admin \u7ad9\u70b9<\/span><br \/>\nadmin<span class=\"token punctuation\">.<\/span>site<span class=\"token punctuation\">.<\/span>register<span class=\"token punctuation\">(<\/span>Project<span class=\"token punctuation\">)<\/span><br \/>\nadmin<span class=\"token punctuation\">.<\/span>site<span class=\"token punctuation\">.<\/span>register<span class=\"token punctuation\">(<\/span>Module<span class=\"token punctuation\">)<\/span><br \/>\nadmin<span class=\"token punctuation\">.<\/span>site<span class=\"token punctuation\">.<\/span>register<span class=\"token punctuation\">(<\/span>TestCase<span class=\"token punctuation\">)<\/span>\n <\/li>\n<li>\n<p>\u542f\u52a8\u5f00\u53d1\u670d\u52a1\u5668&#xff1a;<\/p>\n<p> python manage.py runserver<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;\u670d\u52a1\u5668\u4f1a\u8fd0\u884c\u5728 http:\/\/127.0.0.1:8000\/\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023602-682d3c12d0d26.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u8bbf\u95ee http:\/\/127.0.0.1:8000\/&#xff0c;\u5b89\u88c5\u6210\u529f\u5982\u4e0b\u56fe\u6240\u793a&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023602-682d3c12ec7cc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<li>\n<p>\u8bbf\u95ee Admin \u754c\u9762&#xff1a; \u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00 http:\/\/127.0.0.1:8000\/admin\/\u3002 \u4f7f\u7528\u4f60\u521a\u624d\u521b\u5efa\u7684\u8d85\u7ea7\u7528\u6237\u8d26\u53f7\u767b\u5f55\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023603-682d3c1391377.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u767b\u5f55\u540e&#xff0c;\u4f60\u80fd\u770b\u5230 \u201cAPI\u201d \u90e8\u5206&#xff0c;\u4e0b\u9762\u5217\u51fa\u4e86 \u201c\u6a21\u5757\u5217\u8868\u201d, \u201c\u6d4b\u8bd5\u7528\u4f8b\u5217\u8868\u201d, \u201c\u9879\u76ee\u5217\u8868\u201d\u3002\u4f60\u53ef\u4ee5\u70b9\u51fb\u5b83\u4eec&#xff0c;\u5c1d\u8bd5\u6dfb\u52a0\u4e00\u4e9b\u6d4b\u8bd5\u6570\u636e\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023604-682d3c14086dd.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<p>\u901a\u8fc7 Django Admin \u6dfb\u52a0\u51e0\u6761\u6570\u636e&#xff0c;\u9a8c\u8bc1\u4e0b\u6a21\u578b\u4e4b\u95f4\u7684\u5173\u7cfb\u662f\u5426\u6309\u9884\u671f\u5de5\u4f5c\u3002\u6bd4\u5982&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u521b\u5efa\u4e00\u4e2a\u9879\u76ee \u201c\u7535\u5546\u5e73\u53f0\u6d4b\u8bd5\u201d\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023604-682d3c147a04f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<li>\n<p>\u5728 \u201c\u7535\u5546\u5e73\u53f0\u6d4b\u8bd5\u201d \u9879\u76ee\u4e0b\u521b\u5efa\u4e00\u4e2a\u6a21\u5757 \u201c\u7528\u6237\u767b\u5f55\u6a21\u5757\u201d\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023605-682d3c151e1c0.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<li>\n<p>\u5728 \u201c\u7528\u6237\u767b\u5f55\u6a21\u5757\u201d \u4e0b\u521b\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b \u201cTC001_\u6b63\u786e\u7528\u6237\u540d\u5bc6\u7801\u767b\u5f55\u201d&#xff0c;\u518d\u8f93\u5165\u6d4b\u8bd5\u6b65\u9aa4\u548c\u9884\u671f\u7ed3\u679c\u3002 <img decoding=\"async\" src=\"2025-05-21xdqx1zy3lvn.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<\/ul>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u4f60\u5df2\u7ecf\u6210\u529f\u4e3a\u6d4b\u8bd5\u5e73\u53f0\u8bbe\u8ba1\u4e86\u6838\u5fc3\u7684\u6570\u636e\u6a21\u578b&#xff0c;\u5e76\u5b66\u4f1a\u4e86\u4ee5\u4e0b\u5185\u5bb9&#xff1a;<\/p>\n<ul>\n<li>\u2705 \u5728 Django \u4e2d\u521b\u5efa App\u3002<\/li>\n<li>\u2705 \u4f7f\u7528 Python \u7c7b\u5b9a\u4e49 Django Models (Project, Module, TestCase)\u3002<\/li>\n<li>\u2705 \u7406\u89e3\u4e86\u5b57\u6bb5\u7c7b\u578b\u3001\u5916\u952e\u5173\u7cfb (ForeignKey)\u3001\u5143\u6570\u636e (class Meta) \u7684\u57fa\u672c\u7528\u6cd5\u3002<\/li>\n<li>\u2705 \u751f\u6210\u5e76\u5e94\u7528\u4e86\u6570\u636e\u5e93\u8fc1\u79fb (makemigrations, migrate)\u3002<\/li>\n<li>\u2705 \u901a\u8fc7 Django Admin \u5feb\u901f\u9a8c\u8bc1\u4e86\u6a21\u578b\u3002<\/li>\n<\/ul>\n<p>\u5728\u4e0b\u4e00\u7bc7\u6587\u7ae0\u4e2d&#xff0c;\u6211\u4eec\u5c06\u57fa\u4e8e\u8fd9\u4e9b\u6a21\u578b&#xff0c;\u5f00\u59cb\u4f7f\u7528 Django REST Framework (DRF) \u6765\u521b\u5efa\u540e\u7aef API \u63a5\u53e3&#xff0c;\u8ba9\u524d\u7aef\u80fd\u591f\u901a\u8fc7\u7f51\u7edc\u6765\u8bfb\u53d6\u548c\u64cd\u4f5c\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb808\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf16\u6b21\u3002\u4ec0\u4e48\u662f\u6570\u636e\u6a21\u578b\uff1f\u7b80\u5355\u6765\u8bf4\uff0c\u6570\u636e\u6a21\u578b\u5c31\u662f\u6211\u4eec\u6d4b\u8bd5\u5e73\u53f0\u9700\u8981\u5b58\u50a8\u548c\u7ba1\u7406\u7684\u4fe1\u606f\u7684\u84dd\u56fe\u3002\u6bd4\u5982\uff0c\u4e00\u4e2a\u6d4b\u8bd5\u5e73\u53f0\u80af\u5b9a\u8981\u6709\u201c\u9879\u76ee\u201d\u3001\u201c\u6d4b\u8bd5\u7528\u4f8b\u201d\u3001\u201c\u6d4b\u8bd5\u62a5\u544a\u201d\u8fd9\u4e9b\u4e1c\u897f\uff0c\u6570\u636e\u6a21\u578b\u5c31\u662f\u7528\u6765\u7cbe\u786e\u5b9a\u4e49\u8fd9\u4e9b\u201c\u4e1c\u897f\u201d\u5305\u542b\u54ea\u4e9b\u4fe1\u606f\uff08\u6bd4\u5982\u9879\u76ee\u540d\u79f0\u3001\u7528\u4f8b\u6b65\u9aa4\u3001\u62a5\u544a\u7ed3\u679c\u7b49\uff09\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u662f\u5982\u4f55\u5173\u8054\u7684\u3002\u5728 Django \u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 Models \u6765\u5b9a\u4e49\u6570\u636e\u6a21\u578b\u3002\u4f60\u53ea\u9700\u8981\u7528 Python \u4ee3\u7801\u6765\u63cf\u8ff0\u4f60\u7684\u6570\u636e\u7ed3\u6784\uff0cDjango \u4f1a\u81ea\u52a8\u5e2e\u4f60\u5904\u7406\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u7684\u590d\u6742\u7ec6\u8282\uff08\u6bd4\u5982\u521b\u5efa\u6570\u636e\u5e93\u8868\uff09\u3002<\/p>\n","protected":false},"author":2,"featured_media":38829,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[890,3442,81,292,3449,3443],"topic":[],"class_list":["post-38849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-django","tag-django-vue3-","tag-python","tag-292","tag-3449","tag-3443"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/38849.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb808\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf16\u6b21\u3002\u4ec0\u4e48\u662f\u6570\u636e\u6a21\u578b\uff1f\u7b80\u5355\u6765\u8bf4\uff0c\u6570\u636e\u6a21\u578b\u5c31\u662f\u6211\u4eec\u6d4b\u8bd5\u5e73\u53f0\u9700\u8981\u5b58\u50a8\u548c\u7ba1\u7406\u7684\u4fe1\u606f\u7684\u84dd\u56fe\u3002\u6bd4\u5982\uff0c\u4e00\u4e2a\u6d4b\u8bd5\u5e73\u53f0\u80af\u5b9a\u8981\u6709\u201c\u9879\u76ee\u201d\u3001\u201c\u6d4b\u8bd5\u7528\u4f8b\u201d\u3001\u201c\u6d4b\u8bd5\u62a5\u544a\u201d\u8fd9\u4e9b\u4e1c\u897f\uff0c\u6570\u636e\u6a21\u578b\u5c31\u662f\u7528\u6765\u7cbe\u786e\u5b9a\u4e49\u8fd9\u4e9b\u201c\u4e1c\u897f\u201d\u5305\u542b\u54ea\u4e9b\u4fe1\u606f\uff08\u6bd4\u5982\u9879\u76ee\u540d\u79f0\u3001\u7528\u4f8b\u6b65\u9aa4\u3001\u62a5\u544a\u7ed3\u679c\u7b49\uff09\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u662f\u5982\u4f55\u5173\u8054\u7684\u3002\u5728 Django \u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 Models \u6765\u5b9a\u4e49\u6570\u636e\u6a21\u578b\u3002\u4f60\u53ea\u9700\u8981\u7528 Python \u4ee3\u7801\u6765\u63cf\u8ff0\u4f60\u7684\u6570\u636e\u7ed3\u6784\uff0cDjango \u4f1a\u81ea\u52a8\u5e2e\u4f60\u5904\u7406\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u7684\u590d\u6742\u7ec6\u8282\uff08\u6bd4\u5982\u521b\u5efa\u6570\u636e\u5e93\u8868\uff09\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38849.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-21T02:36:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023559-682d3c0f68663.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38849.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38849.html\",\"name\":\"\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-21T02:36:06+00:00\",\"dateModified\":\"2025-05-21T02:36:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38849.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38849.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38849.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/38849.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb808\u6b21\uff0c\u70b9\u8d5e22\u6b21\uff0c\u6536\u85cf16\u6b21\u3002\u4ec0\u4e48\u662f\u6570\u636e\u6a21\u578b\uff1f\u7b80\u5355\u6765\u8bf4\uff0c\u6570\u636e\u6a21\u578b\u5c31\u662f\u6211\u4eec\u6d4b\u8bd5\u5e73\u53f0\u9700\u8981\u5b58\u50a8\u548c\u7ba1\u7406\u7684\u4fe1\u606f\u7684\u84dd\u56fe\u3002\u6bd4\u5982\uff0c\u4e00\u4e2a\u6d4b\u8bd5\u5e73\u53f0\u80af\u5b9a\u8981\u6709\u201c\u9879\u76ee\u201d\u3001\u201c\u6d4b\u8bd5\u7528\u4f8b\u201d\u3001\u201c\u6d4b\u8bd5\u62a5\u544a\u201d\u8fd9\u4e9b\u4e1c\u897f\uff0c\u6570\u636e\u6a21\u578b\u5c31\u662f\u7528\u6765\u7cbe\u786e\u5b9a\u4e49\u8fd9\u4e9b\u201c\u4e1c\u897f\u201d\u5305\u542b\u54ea\u4e9b\u4fe1\u606f\uff08\u6bd4\u5982\u9879\u76ee\u540d\u79f0\u3001\u7528\u4f8b\u6b65\u9aa4\u3001\u62a5\u544a\u7ed3\u679c\u7b49\uff09\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u662f\u5982\u4f55\u5173\u8054\u7684\u3002\u5728 Django \u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 Models \u6765\u5b9a\u4e49\u6570\u636e\u6a21\u578b\u3002\u4f60\u53ea\u9700\u8981\u7528 Python \u4ee3\u7801\u6765\u63cf\u8ff0\u4f60\u7684\u6570\u636e\u7ed3\u6784\uff0cDjango \u4f1a\u81ea\u52a8\u5e2e\u4f60\u5904\u7406\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u7684\u590d\u6742\u7ec6\u8282\uff08\u6bd4\u5982\u521b\u5efa\u6570\u636e\u5e93\u8868\uff09\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/38849.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-21T02:36:06+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521023559-682d3c0f68663.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38849.html","url":"https:\/\/www.wsisp.com\/helps\/38849.html","name":"\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-21T02:36:06+00:00","dateModified":"2025-05-21T02:36:06+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38849.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38849.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38849.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e09\u3001\u3010\u6570\u636e\u5efa\u6a21\u7bc7\u3011\uff1a\u7528 Django Models \u6784\u5efa\u6d4b\u8bd5\u5e73\u53f0\u6838\u5fc3\u6570\u636e"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=38849"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38849\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/38829"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38849"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}