From bdb75818bcd29ddbac24bc6e16ea3ecca1d34d0e Mon Sep 17 00:00:00 2001 From: Salman Ashraf Date: Tue, 9 Jul 2024 08:38:07 +0000 Subject: [PATCH] change model fields --- api/models/agreement_signature.py | 17 ++++++++--------- api/models/agreement_signature_test.py | 0 api/models/contributor_test.py | 0 api/models/repository.py | 17 ++++++++--------- api/models/repository_test.py | 0 5 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 api/models/agreement_signature_test.py create mode 100644 api/models/contributor_test.py create mode 100644 api/models/repository_test.py diff --git a/api/models/agreement_signature.py b/api/models/agreement_signature.py index 94554d9..c44e1ac 100644 --- a/api/models/agreement_signature.py +++ b/api/models/agreement_signature.py @@ -3,30 +3,29 @@ Created on 08/07/2024 at 10:48:44(+01:00). """ + import typing as t from django.db import models from django.utils.translation import gettext_lazy as _ -from .contributor import Contributor if t.TYPE_CHECKING: from django_stubs_ext.db.models import TypedModelMeta + + from .contributor import Contributor else: TypedModelMeta = object - class AgreementSignature(models.Model): """ Signature of a contributor signing the agreement """ - id = models.AutoField(primary_key=True) contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) agreement_id = models.CharField(max_length=40) signed_at = models.DateTimeField() - - def __str__(self): - return self.id class Meta: - constraints = [ - models.UniqueConstraint(fields=["contributor", "agreement_id"], name='unique_contributor_agreement') - ] \ No newline at end of file + unique_together = ["contributor", "agreement_id"] + + def __str__(self): + return f"Contributor {self.contributor} signed + {self.agreement_id[:7]} at {self.signed_at}" \ No newline at end of file diff --git a/api/models/agreement_signature_test.py b/api/models/agreement_signature_test.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models/contributor_test.py b/api/models/contributor_test.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models/repository.py b/api/models/repository.py index 8a55448..d112df6 100644 --- a/api/models/repository.py +++ b/api/models/repository.py @@ -8,10 +8,11 @@ from django.db import models from django.utils.translation import gettext_lazy as _ -from .contributor import Contributor if t.TYPE_CHECKING: from django_stubs_ext.db.models import TypedModelMeta + + from .contributor import Contributor else: TypedModelMeta = object @@ -19,17 +20,15 @@ class Repository(models.Model): """ A repository to contribute to""" id = models.IntegerField(primary_key=True) contributor = models.ForeignKey(Contributor, on_delete=models.CASCADE) - name_choices = [ + NAME_CHOICES = [ ("portal", "portal"), ("rr", "rr") ] - name = models.TextField(choices=name_choices) + name = models.TextField(choices=NAME_CHOICES) points = models.IntegerField(default=0) - - def __str__(self): - return self.name class Meta: - constraints = [ - models.UniqueConstraint(fields=["contributor", "name"], name='unique_contributor_repo') - ] \ No newline at end of file + unique_together = ["contributor", "name"] + + def __str__(self): + return self.name \ No newline at end of file diff --git a/api/models/repository_test.py b/api/models/repository_test.py new file mode 100644 index 0000000..e69de29