Applies model generics on relational fields functions#2156
Applies model generics on relational fields functions#2156ropmyung wants to merge 4 commits intotortoise:developfrom
Conversation
|
Why do that? What's the benefit? |
Of course for type hint. Otherwise, It shows like Model, not the specific model class |
|
Could you show a demo of how 'Model' raises a type issue, while 'MODEL' does not? |
|
OK, get it. Seems that the |
|
The following lines should be changed also: |
|
@ropmyung, would you like to introduce generic syntax for |
|
Oops, sorry I was too busy because of university stuff. I'll be happy if anyone addresses that; otherwise let me try implementing the |
|
@ropmyung Please fix lint issue, it can be: +++ b/tests/migrations/test_schema_editor_sql.py
@@ -89,7 +89,9 @@ async def test_add_field_m2m_generates_table_sql() -> None:
class WidgetWithTags(Model):
id = fields.IntField(pk=True)
- tags = fields.ManyToManyField("models.Tag", related_name="widgets")
+ tags: fields.ManyToManyRelation[Tag] = fields.ManyToManyField(
+ "models.Tag", related_name="widgets"
+ )
class Meta:
table = "widget"
diff --git a/tests/testmodels.py b/tests/testmodels.py
index 24ca2fa9..62b3b23f 100644
--- a/tests/testmodels.py
+++ b/tests/testmodels.py
@@ -1152,7 +1152,9 @@ class Flavor(Model):
class Drink(Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=100)
- flavors = fields.ManyToManyField("models.Flavor", related_name="drinks", through="drink_flavor")
- toppings = fields.ManyToManyField(
+ flavors: fields.ManyToManyRelation[Flavor] = fields.ManyToManyField(
+ "models.Flavor", related_name="drinks", through="drink_flavor"
+ )
+ toppings: fields.ManyToManyRelation[Flavor] = fields.ManyToManyField(
"models.Flavor", related_name="topping_drinks", through="drink_topping"
) |
Co-authored-by: Copilot <copilot@github.com>
|
If you are using Linux/MacOS, run the following command to auto fix style issue: And for Windows, you can do it by: |
|
@ropmyung You can run |


Description
Applied generic syntax on relational fields functions for type hinting
ForeignKeyField
OneToOneField