Ajout de la date de création/mise à jour dans le modèle Participants
This commit is contained in:
parent
99e3438ead
commit
14e8d963d6
4 changed files with 39 additions and 6 deletions
|
@ -2,5 +2,11 @@ from django.contrib import admin
|
||||||
|
|
||||||
from .models import Event, Participants
|
from .models import Event, Participants
|
||||||
|
|
||||||
|
class ParticipantsAdmin(admin.ModelAdmin):
|
||||||
|
fields = ["event", "participant", "reponse", "instrument", "instrument_autre", "dont_play_main", "details", "creationDate", "updateDate" ]
|
||||||
|
readonly_fields = [ "creationDate", "updateDate" ]
|
||||||
|
list_display = ["participant", "event", "reponse", "creationDate", "updateDate" ]
|
||||||
|
|
||||||
# Add event by admin page return a 502 error
|
# Add event by admin page return a 502 error
|
||||||
admin.site.register(Event)
|
admin.site.register(Event)
|
||||||
|
admin.site.register(Participants, ParticipantsAdmin)
|
||||||
|
|
25
calendrier/migrations/0007_auto_20220314_2320.py
Normal file
25
calendrier/migrations/0007_auto_20220314_2320.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 2.2.25 on 2022-03-14 23:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('calendrier', '0006_auto_20210929_1629'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='participants',
|
||||||
|
name='creationDate',
|
||||||
|
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Date de création'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='participants',
|
||||||
|
name='updateDate',
|
||||||
|
field=models.DateTimeField(auto_now=True, verbose_name='Dernière mise à jour'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -73,3 +73,5 @@ class Participants(models.Model):
|
||||||
choices=[("Non", _("Non")), ("Oui", _("Oui"))],
|
choices=[("Non", _("Non")), ("Oui", _("Oui"))],
|
||||||
)
|
)
|
||||||
details = models.CharField(max_length=50, blank=True)
|
details = models.CharField(max_length=50, blank=True)
|
||||||
|
creationDate = models.DateTimeField(auto_now_add=True, verbose_name = _("Date de création"))
|
||||||
|
updateDate = models.DateTimeField(auto_now=True, verbose_name = _("Dernière mise à jour"))
|
||||||
|
|
|
@ -373,16 +373,16 @@ class ReponseEvent(LoginRequiredMixin, TemplateView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
form = self.form_class(request.POST)
|
|
||||||
ev = get_object_or_404(Event, id=self.kwargs["id"])
|
ev = get_object_or_404(Event, id=self.kwargs["id"])
|
||||||
part = request.user.profile
|
part = request.user.profile
|
||||||
|
try:
|
||||||
|
p = Participants.objects.get(event=ev, participant=part)
|
||||||
|
except Participants.DoesNotExist:
|
||||||
|
p = None
|
||||||
|
form = self.form_class(request.POST, instance = p)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
try:
|
|
||||||
p = Participants.objects.get(event=ev, participant=part)
|
|
||||||
p.delete()
|
|
||||||
except Participants.DoesNotExist:
|
|
||||||
pass
|
|
||||||
obj = form.save(commit=False)
|
obj = form.save(commit=False)
|
||||||
|
# Si la participation existe déjà, ces 2 ligne sont redondantes
|
||||||
obj.event = ev
|
obj.event = ev
|
||||||
obj.participant = part
|
obj.participant = part
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
Loading…
Reference in a new issue