Replies: 1 comment
-
If you want the type for the implicit through model you'll need to type it out. And once you've typed it out, you might as well use it during runtime, though that's probably not a requirement. But here's the updated models that uses the through model during runtime: # models.py
-from django.db.models import ManyToManyField, Model
+from django.db.models import ForeignKey, ManyToManyField, Model, UniqueConstraint
class A(Model):
class Meta:
pass
+class AB(Model):
+ a = ForeignKey(A, on_delete=models.CASCADE)
+ b = ForeignKey("app.B", on_delete=models.CASCADE)
+
+ class Meta:
+ constraints = [UniqueConstraint(fields=["a", "b"], name="a_b_unq")]
+
+
class B(Model):
- a_models = ManyToManyField(to=A, related_name="b_models")
+ a_models = ManyToManyField(to=A, through=AB, related_name="b_models")
class Meta:
pass |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a the following models
and in the Admin I want to use InlineAdminModel to show the
B
also inA
Mypy complains now:
How do I create a type annotation
B_a_models
?Beta Was this translation helpful? Give feedback.
All reactions