Skip to content

Commit

Permalink
[#203] Add related_name to avoid conflicts when subclassing. (#228)
Browse files Browse the repository at this point in the history
* [#203] Add related_name to avoid conflicts when subclassing.

* Add tests for invitation related_name and related_query_name

---------

Co-authored-by: blag <[email protected]>
  • Loading branch information
mdrie and blag authored Dec 30, 2023
1 parent c3162d2 commit 4235da2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions invitations/base_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class AbstractBaseInvitation(models.Model):
null=True,
blank=True,
on_delete=models.CASCADE,
related_name="%(app_label)s_%(class)ss",

This comment has been minimized.

Copy link
@Flimm

Flimm Jun 13, 2024

Contributor

This change requires a migration file to be created. I created it in this commit:

8ae641f

related_query_name="%(app_label)s_%(class)s",
)

objects = BaseInvitationManager()
Expand Down
13 changes: 13 additions & 0 deletions tests/basic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ def test_invitation_key_expiry(self, invitation_a):
)
assert invitation_a.key_expired() is False

def test_invitation_related_name(self, sent_invitation_by_user_a):
user = sent_invitation_by_user_a.inviter
assert user.invitations_invitations.all()
assert user.invitations_invitations.count() == 1

def test_invitation_related_query_name(self, sent_invitation_by_user_a):
assert (
Invitation.objects.filter(
inviter__invitations_invitation__id=sent_invitation_by_user_a.pk
).count()
== 1
)


class TestInvitationsAdapter:
def test_fetch_adapter(self):
Expand Down

0 comments on commit 4235da2

Please sign in to comment.