Skip to content

Commit

Permalink
Merge pull request #112 from dimagi/pkv/fix-opportunity-access-model-…
Browse files Browse the repository at this point in the history
…user-foreign-key

Remove OneToOne user, add unique_together user and opportunity on Opportunity Access
  • Loading branch information
pxwxnvermx authored Sep 13, 2023
2 parents cdb2f7e + 7cbce7e commit 73c56ab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.3 on 2023-09-12 05:21

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("opportunity", "0015_remove_opportunityaccess_date_claimed"),
]

operations = [
migrations.AlterField(
model_name="opportunityaccess",
name="user",
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AlterUniqueTogether(
name="opportunityaccess",
unique_together={("user", "opportunity")},
),
]
5 changes: 4 additions & 1 deletion commcare_connect/opportunity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Assessment(XFormBaseModel):


class OpportunityAccess(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
opportunity = models.ForeignKey(Opportunity, on_delete=models.CASCADE)
date_learn_started = models.DateTimeField(null=True)

Expand Down Expand Up @@ -166,6 +166,9 @@ def last_visit_date(self):

return

class Meta:
unique_together = ("user", "opportunity")


class VisitValidationStatus(models.TextChoices):
pending = "pending", gettext("Pending")
Expand Down

0 comments on commit 73c56ab

Please sign in to comment.