-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix: User default language based on browser language #2201
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
name='language', | ||
field=models.CharField(default=None, max_length=10, null=True, verbose_name='语言'), | ||
), | ||
] |
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.
Your migration looks generally correct, but there are a few things you might consider:
-
Default Value for
null
: The default value ofNone
can be ambiguous because in Python, many types cannot be determined from justNone
. If you want to explicitly indicate that null is allowed, it's better to usemodels.TextField(null=True)
instead. -
Verbose Name: In Django, you typically only need to specify the verbose name if you're not using the default translation system, which is common these days. You could remove it entirely:
field=models.CharField(max_length=10, null=True),
-
Consistent Field Definition: It would also make sense to have all fields defined consistently (e.g., whether they're required or optional). For example,
blank=True
could be added for any non-required string fields:field=models.CharField(max_length=10, blank=True, null=True),
Here's an optimized version based on these suggestions:
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.18 on 2025-02-10 06:01
+from django.db import migrations, models
+class Migration(migrations.Migration):
+ dependencies = [
+ ('application', '0025_alter_application_prologue'),
+ ]
+ operations = [
+ migrations.AlterField(
+ model_name='applicationaccesstoken',
+ name='language',
+ field=models.CharField(max_length=10, blank=True, null=True),
+ ),
+ ]
This version simplifies the model definition while maintaining clarity.
name='language', | ||
field=models.CharField(default=None, max_length=10, null=True, verbose_name='语言'), | ||
), | ||
] |
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.
No issues found in your migration script. The structure is correct and follows best practices for altering fields in Django database migrations.
@@ -50,7 +50,7 @@ class ApplicationAccessToken(AppModelMixin): | |||
, default=list) | |||
show_source = models.BooleanField(default=False, verbose_name="是否显示知识来源") | |||
|
|||
language = models.CharField(max_length=10, verbose_name="语言", default=get_language) | |||
language = models.CharField(max_length=10, verbose_name="语言", default=None, null=True) | |||
|
|||
class Meta: | |||
db_table = "application_access_token" |
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.
This code has some minor adjustments to improve clarity and functionality:
- Null Check: The
language
field is now set to acceptnull=True
, which allows for the possibility that it could be left empty.
language = models.CharField(max_length=10, verbose_name="语言", default=None, null=True)
-
Default Value Removal: Removed the call to
get_language
in the default value of thelanguage
field since it no longer returns an object (it used to return either 'zh_CN' or 'en_US'). Instead, simply set it toNone
. -
Minor Typographical Correction:
- Changed
verbose_name("是否显示知识来源")
toverbose_name='是否显示知识来源'
.
- Changed
This should make the function more robust and handle edge cases like when the default
option needs to be None
.
fix: User default language based on browser language