-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor: remove tool_type field and update imports in tool model #2926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,15 @@ | ||
| import uuid_utils.compat as uuid | ||
| from django.db import models | ||
|
|
||
| from .tool_module import ToolModule | ||
| from users.models import User | ||
| from .tool_module import ToolModule | ||
|
|
||
|
|
||
| class ToolScope(models.TextChoices): | ||
| SHARED = "SHARED", '共享' | ||
| WORKSPACE = "WORKSPACE", "工作空间可用" | ||
|
|
||
|
|
||
| class ToolType(models.TextChoices): | ||
| INTERNAL = "INTERNAL", '内置' | ||
| PUBLIC = "PUBLIC", "公开" | ||
|
|
||
|
|
||
| class Tool(models.Model): | ||
| id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id") | ||
| user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户id") | ||
|
|
@@ -27,8 +22,6 @@ class Tool(models.Model): | |
| is_active = models.BooleanField(default=True) | ||
| scope = models.CharField(max_length=20, verbose_name='可用范围', choices=ToolScope.choices, | ||
| default=ToolScope.WORKSPACE) | ||
| tool_type = models.CharField(max_length=20, verbose_name='函数类型', choices=ToolType.choices, | ||
| default=ToolType.PUBLIC) | ||
| template_id = models.UUIDField(max_length=128, verbose_name="模版id", null=True, default=None) | ||
| module = models.ForeignKey(ToolModule, on_delete=models.CASCADE, verbose_name="模块id", default='root') | ||
| workspace_id = models.CharField(max_length=64, verbose_name="工作空间id", default="default", db_index=True) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a concise list of review points to improve the code:
Suggested Changesimport uuid_utils.compat as uuid
from django.db import models
class Tool(models.Model):
# Primary key for this tool instance
ID_FIELD = 'id'
id = models.UUIDField(
primary_key=True,
max_length=128,
default=uuid.uuid7,
editable=False,
verbose_name="主键ID",
)
# User who owns this tool
USER_FIELD = 'user'
user = models.ForeignKey(
UserModel, # Replace UserModel with actual User model from apps.users.models
on_delete=models.CASCADE,
related_name='tools',
verbose_name="用户ID",
)
WORKSPACE_ID_FIELD = 'workspace_id'
workspace_id = models.CharField(
max_length=64,
db_index=True,
blank=True,
null=True,
default="default",
verbose_name="工作空间ID",
)
MODULE_FIELD = 'module'
module = models.ForeignKey(
ToolModule,
on_delete=models.CASCADE,
related_name='tools',
verbose_name="模块名称",
)Replace |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code snippet has a minor issue with the
tool_typefield. It seems you might want to remove this field since it's not used within the class logic but is present due to some migration migration process that didn't clear these extraneous fields.Here’s an optimized version of the
Migrationclass:Explanation:
tool_typefield from both the model creation and modification parts.tool_typeshould be part of a different model (perhaps named differently).Make sure to adjust the field names and data types according to your actual application requirements.