forked from beba/foerderbarometer
added a presave signal for travel model to update own field with foreign key project field
This commit is contained in:
parent
37e629de70
commit
b451cbbb16
|
@ -32,7 +32,7 @@ class ProjectAdmin(admin.ModelAdmin):
|
|||
search_fields = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status')
|
||||
list_display = ('name', 'pid','finance_id', 'realname', 'start', 'end', 'participants_estimated', 'participants_real', 'cost', 'status')
|
||||
# action = ['export_as_csv']
|
||||
date_hierarchy = 'start'
|
||||
date_hierarchy = 'end'
|
||||
|
||||
|
||||
@admin.register(BusinessCard)
|
||||
|
|
|
@ -66,6 +66,7 @@ class TravelForm(FdbForm):
|
|||
self.fields['checkin'].required = True
|
||||
self.fields['checkout'].required = True
|
||||
self.fields['hotel'].required = True
|
||||
self.fields['project_end'].required = False
|
||||
|
||||
class Meta:
|
||||
model = Travel
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.1.2 on 2022-12-05 18:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('input', '0083_auto_20221205_0946'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='travel',
|
||||
name='project_end',
|
||||
field=models.DateField(null=True, verbose_name='Projektende'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.1.2 on 2022-12-05 18:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('input', '0084_travel_project_end'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='travel',
|
||||
name='project_end',
|
||||
field=models.DateField(blank=True, null=True, verbose_name='Projektende'),
|
||||
),
|
||||
]
|
|
@ -87,9 +87,10 @@ class Project(Volunteer):
|
|||
notes = models.TextField(max_length=1000,null=True,blank=True,verbose_name='Anmerkungen')
|
||||
intern_notes = models.TextField(max_length=1000, blank=True, verbose_name="interne Anmerkungen")
|
||||
|
||||
end_mail_send = models.BooleanField(null=True, verbose_name='Endmail versenden')
|
||||
|
||||
# the following Fields are not supposed to be edited by users
|
||||
pid = models.CharField(max_length=15, null=True, blank=True)
|
||||
end_mail_send = models.BooleanField(null=True, verbose_name='Endmail versenden')
|
||||
status = models.CharField(max_length=3,choices=(('RUN', 'läuft'),('END','beendet'),('NOT','nicht stattgefunden')),default='RUN')
|
||||
persons = models.IntegerField(default=1)
|
||||
finance_id = models.CharField(max_length=15, null= True, blank=True)
|
||||
|
@ -149,6 +150,8 @@ TRANSPORT_CHOICES = {'BAHN': 'Bahn',
|
|||
PAYEDBY_CHOICES = {'WMDE': 'WMDE',
|
||||
'REQU': 'Antragstellender Mensch'}
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
class Travel(Volunteer):
|
||||
# project variable is now null true and blank true, which means it can be saved without project id to be later on filled out by admins
|
||||
project = models.ForeignKey(Project, on_delete=models.CASCADE, null=True, blank=True)
|
||||
|
@ -164,6 +167,26 @@ class Travel(Volunteer):
|
|||
notes = models.TextField(max_length=1000, blank=True, verbose_name='Anmerkungen')
|
||||
request_url = models.URLField(max_length=2000, verbose_name='Antrag (URL)')
|
||||
intern_notes = models.TextField(max_length=1000, blank=True, verbose_name='interne Anmerkungen')
|
||||
project_end = models.DateField(blank=True, null=True, verbose_name='Projektende')
|
||||
# use content type model to get the end date for the project foreign key
|
||||
|
||||
|
||||
from django.db.models.signals import pre_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
@receiver(pre_save, sender=Travel, dispatch_uid="get_project_end")
|
||||
def getProjectEnd(sender, instance, **kwargs):
|
||||
#instance.project_end = instance.project.end
|
||||
instance.project_end = instance.project.end
|
||||
|
||||
|
||||
# def save(self,*args,**kwargs):
|
||||
# '''we generate the autogenerated fields here'''
|
||||
# # we don't call save with args/kwargs to avoid UNIQUE CONSTRAINT errors
|
||||
# # but maybe there is a better solution?
|
||||
# intern_notes
|
||||
# project_end = self.checkout
|
||||
# super(Travel, self).save(*args,**kwargs)
|
||||
|
||||
#abstract base class for Library and IFG
|
||||
class Grant(Extern):
|
||||
|
|
Loading…
Reference in New Issue