You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.3 KiB

4 years ago
4 years ago
  1. from django.db import models
  2. from .settings import ACCOUNTS
  3. class Volunteer(models.Model):
  4. realname = models.CharField(max_length=200, null=True)
  5. email = models.CharField(max_length=200, null=True)
  6. username = models.CharField(max_length=200, null=True)
  7. granted = models.BooleanField(null=True)
  8. @classmethod
  9. def set_granted(cl, key, b):
  10. obj = cl.objects.get(pk=key)
  11. obj.granted = b
  12. obj.save()
  13. class Meta:
  14. abstract = True
  15. class Project(Volunteer):
  16. name = models.CharField(max_length=200)
  17. start = models.DateField('start date')
  18. account = models.CharField(max_length=5, choices=ACCOUNTS.items())
  19. pid = models.IntegerField(null=True, blank=True) # automaticly generated
  20. def save(self,*args,**kwargs):
  21. # is there a way to call super().save() only once?
  22. super().save(*args,*kwargs)
  23. self.pid = 10000 + self.pk
  24. super().save(*args,*kwargs)
  25. def __str__(self):
  26. return f"{self.pid} {self.name}"
  27. class HonoraryCertificate(Volunteer):
  28. request_url = models.CharField(max_length=2000)
  29. project = models.ForeignKey(Project, null = True, on_delete = models.SET_NULL)
  30. def __str__(self):
  31. return "Certificate for " + self.realname
  32. #abstract class for Library, IFG, ...
  33. class Grant(Volunteer):
  34. cost = models.CharField(max_length=10)
  35. notes = models.CharField(max_length=500)
  36. class Meta:
  37. abstract = True
  38. TYPE_CHOICES = [('BIB', 'Bibliotheksstipendium'),
  39. ('ELIT', 'eLiteraturstipendium'),
  40. ('SOFT', 'Softwarestipendium'),
  41. ('VIS', 'Visitenkarten'),
  42. ('LIST', 'Mailingliste'),
  43. ('MAIL', 'E-Mail-Adresse'),
  44. ('IFG', 'Kostenübernahme IFG-Anfrage'),
  45. ('LIT', 'Literaturstipendium'),]
  46. # same model is used for Library, ELitStip and Software!
  47. class Library(Grant):
  48. type = models.CharField(
  49. max_length=4,
  50. choices=TYPE_CHOICES, #attention: actually only BIB, ELIT, SOFT should be used here
  51. default='LIB',
  52. )
  53. library = models.CharField(max_length=200)
  54. duration = models.CharField(max_length=100)
  55. def __str__(self):
  56. return self.library
  57. class IFG(Grant):
  58. url = models.CharField(max_length=2000)
  59. def __str__(self):
  60. return "IFG-Anfrage von " + self.realname