Skip to content

Commit

Permalink
Add related_name to models
Browse files Browse the repository at this point in the history
  • Loading branch information
pxwxnvermx committed Oct 12, 2023
1 parent 90c5131 commit d04b91c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-10-12 08:20
# Generated by Django 4.2.5 on 2023-10-12 11:58

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -27,14 +27,22 @@ class Migration(migrations.Migration):
model_name="deliverunit",
name="payment_unit",
field=models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="opportunity.paymentunit"
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="deliver_units",
related_query_name="deliver_unit",
to="opportunity.paymentunit",
),
),
migrations.AddField(
model_name="payment",
name="payment_unit",
field=models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="opportunity.paymentunit"
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="payments",
related_query_name="payment",
to="opportunity.paymentunit",
),
),
]
16 changes: 14 additions & 2 deletions commcare_connect/opportunity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ class DeliverUnit(models.Model):
)
slug = models.SlugField(max_length=100)
name = models.CharField(max_length=255)
payment_unit = models.ForeignKey(PaymentUnit, on_delete=models.CASCADE, null=True)
payment_unit = models.ForeignKey(
PaymentUnit,
on_delete=models.CASCADE,
related_name="deliver_units",
related_query_name="deliver_unit",
null=True,
)

def __str__(self):
return self.name
Expand All @@ -193,7 +199,13 @@ class Payment(models.Model):
amount = models.PositiveIntegerField()
date_paid = models.DateTimeField(auto_now_add=True)
opportunity_access = models.ForeignKey(OpportunityAccess, on_delete=models.DO_NOTHING, null=True, blank=True)
payment_unit = models.ForeignKey(PaymentUnit, on_delete=models.CASCADE, null=True)
payment_unit = models.ForeignKey(
PaymentUnit,
on_delete=models.CASCADE,
related_name="payments",
related_query_name="payment",
null=True,
)


class UserVisit(XFormBaseModel):
Expand Down

0 comments on commit d04b91c

Please sign in to comment.