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.

77 lines
2.2 KiB

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