Skip to content
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

Bug/through table dunder syntax fails in 1.3.3 #274

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/generic/models.py
Expand Up @@ -220,6 +220,20 @@ class RelatedNamesWithEmptyDefaultsModel(models.Model):
)


class Player(models.Model):
name = models.CharField(max_length=128)
playlist = models.ManyToManyField("Content", through="PlayerContent")


class Content(models.Model):
name = models.CharField(max_length=128)


class PlayerContent(models.Model):
player = models.ForeignKey(Player, on_delete=models.CASCADE)
content = models.ForeignKey(Content, on_delete=models.CASCADE)


class ModelWithOverridedSave(Dog):
def save(self, *args, **kwargs):
self.owner = kwargs.pop("owner")
Expand Down Expand Up @@ -331,7 +345,6 @@ class DummyImageFieldModel(models.Model):
fs = FileSystemStorage(location=gettempdir())
image_field = models.ImageField(upload_to="%Y/%m/%d", storage=fs)


else:
# doesn't matter, won't be using
class DummyImageFieldModel(models.Model):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_filling_fields.py
Expand Up @@ -329,6 +329,15 @@ def test_filling_optional_foreignkey_implicitly(self):
assert dummy.cake.name == "Carrot cake"


@pytest.mark.django_db
def test_filling_foreignkeys_on_through_table_with_dunder_syntax():
dummy = baker.make(
models.PlayerContent, content__name="Indiana Jones", player__name="TV"
)
assert dummy.content.name == "Indiana Jones"
assert dummy.player.name == "TV"


@pytest.mark.django_db
class TestsFillingFileField:
def test_filling_file_field(self):
Expand Down