diff --git a/django_api/models.py b/django_api/models.py index 6630662a..2e0c90be 100644 --- a/django_api/models.py +++ b/django_api/models.py @@ -1,212 +1,212 @@ from django.db import models from django.contrib.auth.models import User import datetime from django.utils.translation import gettext as _ # Ref: database_model_20210421_MB.drawio 21.04.2021 class Country(models.Model): name = models.CharField(verbose_name="Country name", max_length=120, null=True) iso_code = models.CharField(max_length=3, null=True) def __str__(self): return f"{self.name}" class Meta: ordering = ('name',) class Language(models.Model): name = models.CharField(verbose_name="Language name", max_length=120, null=True) iso_code = models.CharField(max_length=3, null=True) def __str__(self): return f"{self.name}" class Meta: ordering = ('name',) class Oa(models.Model): status = models.CharField(max_length=1000, null=True) description = models.CharField(max_length=1000, null=True) subscription = models.BooleanField(default=False) accepted_manuscript = models.BooleanField(default=False) apc = models.BooleanField(default=False) final_version = models.BooleanField(default=False) def __str__(self): return f"{self.status}" class Meta: ordering = ('-subscription',) class Publisher(models.Model): name = models.CharField(verbose_name="Publisher name", max_length=1000, null=True) city = models.CharField(max_length=100, null=True) state = models.CharField(max_length=3, null=True) country = models.ManyToManyField("Country") starting_year = models.IntegerField() website = models.URLField(max_length=1000) oa_policies = models.URLField(max_length=1000) def __str__(self): return f"{self.name}" class Meta: ordering = ('name',) class Journal(models.Model): name = models.CharField(verbose_name="Journal name", max_length=800, blank=True, null=True) # search journal with name name_short_iso_4 = models.CharField(max_length=300, blank=True, null=True) publisher = models.ManyToManyField(Publisher) website = models.URLField(max_length=300, blank=True, null=True) language = models.ManyToManyField(Language) # issn = models.ManyToManyField("Issn") # search journal with ISSN oa_options = models.URLField(max_length=1000, blank=True, null=True) oa_status = models.ForeignKey("Oa", on_delete=models.CASCADE) starting_year = models.IntegerField(blank=True, null=True) def __str__(self): return f"{self.name} from {self.website}" class Meta: ordering = ('name',) class Issn(models.Model): PRINT = 1 ELECTRONIC = 2 OTHER = 3 TYPE_CHOICES = ( (PRINT, 'Print'), (ELECTRONIC, 'Electronic'), (OTHER, 'Other'), ) issn = models.CharField(max_length=9, null=False) journal = models.ForeignKey(Journal, on_delete=models.CASCADE, blank=True, null=True) # search journal with ISSN issn_type = models.CharField( choices=TYPE_CHOICES, max_length=10, blank=True ) def __str__(self): return f"{self.issn} ({dict(self.TYPE_CHOICES)[int(self.issn_type)]})" class Meta: ordering = ('issn',) class Organization(models.Model): name = models.CharField(verbose_name="Organization name", max_length=600, null=True) website = models.URLField(max_length=600, blank=True, null=True) country = models.ManyToManyField("Country") ror = models.CharField(max_length=255, blank=True, null=True) fundref = models.CharField(max_length=255, blank=True, null=True) starting_year = models.IntegerField(blank=True, null=True) is_funder = models.BooleanField(default=False) def __str__(self): return f"{self.name}" class Meta: ordering = ('name',) class Version(models.Model): description = models.CharField(max_length=300, null=False) def __str__(self): return f"{self.description}" class Licence(models.Model): name_or_abbrev = models.CharField(max_length=300, null=False) website = models.URLField(max_length=600, null=True) def __str__(self): return f"{self.name_or_abbrev}" class Cost_factor_type(models.Model): name = models.CharField(max_length=300, null=False) def __str__(self): return f"{self.name}" class Cost_factor(models.Model): cost_factor_type = models.ForeignKey(Cost_factor_type, on_delete=models.CASCADE, blank=True, null=True) amount = models.IntegerField(null=False) symbol = models.CharField(max_length=10, null=False) comment = models.CharField(max_length=120, default="") def __str__(self): return f"{self.amount} {self.symbol}" class Term(models.Model): version = models.ManyToManyField(Version) cost_factor = models.ManyToManyField(Cost_factor) embargo_months = models.IntegerField(blank=True, null=True) ir_archiving = models.BooleanField(default=False) licence = models.ManyToManyField(Licence) comment = models.CharField(max_length=600, null=True) source = models.URLField(max_length=600, null=True) def __str__(self): # TODO fix this when the actual data become available - # return f"{self.id} about {';'.join([x for x in self.version.all()])} - {self.comment}" - return f"{self.id} - {self.comment}" + return f"{self.id} about {';'.join([x.description for x in self.version.all()])} - {self.comment}" + # return f"{self.id} - {self.comment}" class ConditionType(models.Model): condition_issuer = models.CharField(max_length=300, null=False) def __str__(self): return f"{self.condition_issuer}" class ConditionSet(models.Model): condition_type = models.ForeignKey(ConditionType, on_delete=models.CASCADE, blank=True, null=True) organization = models.ManyToManyField( Organization, through='OrganizationCondition', through_fields=('condition_set', 'organization') ) journal = models.ManyToManyField( Journal, through='JournalCondition', through_fields=('condition_set', 'journal') ) term = models.ManyToManyField(Term) comment = models.CharField(max_length=100, null=True, default=":-)") def __str__(self): return f"{self.id} {self.condition_type}|{self.comment}" class OrganizationCondition(models.Model): organization = models.ForeignKey(Organization, on_delete=models.CASCADE, blank=True, null=True) condition_set = models.ForeignKey(ConditionSet, on_delete=models.CASCADE, blank=True, null=True) valid_from = models.DateField(blank=True, null=True) valid_until = models.DateField(blank=True, null=True) def __str__(self): return f"{self.id} {self.organization}/{self.condition_set}" class JournalCondition(models.Model): journal = models.ForeignKey(Journal, on_delete=models.CASCADE, blank=True, null=True) condition_set = models.ForeignKey(ConditionSet, on_delete=models.CASCADE, blank=True, null=True) valid_from = models.DateField(blank=True, null=True) valid_until = models.DateField(blank=True, null=True) def __str__(self): return f"{self.id} {self.journal.name}/{self.condition_set}"