creates initial models

This commit is contained in:
Ludovic Stephan 2016-07-22 22:48:09 +02:00
parent 3e634e70c1
commit f44b3fc33c
2 changed files with 43 additions and 1 deletions

View file

@ -9,7 +9,7 @@ from django.core.mail import send_mail
from django.contrib import admin from django.contrib import admin
from django.db.models import Sum, Count from django.db.models import Sum, Count
from bda.models import Spectacle, Salle, Participant, ChoixSpectacle,\ from bda.models import Spectacle, Salle, Participant, ChoixSpectacle,\
Attribution, Tirage Attribution, Tirage, SpectacleRevente
from django import forms from django import forms
from datetime import timedelta from datetime import timedelta
@ -204,9 +204,28 @@ class SalleAdmin(admin.ModelAdmin):
search_fields = ('name', 'address') search_fields = ('name', 'address')
class SpectacleReventeAdmin(admin.ModelAdmin):
model = SpectacleRevente
def spectacle(self, obj):
return obj.attribution.spectacle
def participant(self, obj):
return obj.attribution.participant
list_display = ("spectacle", "participant", "date", "sold")
readonly_fields = ("shotgun",)
list_filter = ("sold", )
search_fields = ("spectacle__title",
"participant__user__username",
"participant__user__firstname",
"participant__user__lastname",)
admin.site.register(Spectacle, SpectacleAdmin) admin.site.register(Spectacle, SpectacleAdmin)
admin.site.register(Salle, SalleAdmin) admin.site.register(Salle, SalleAdmin)
admin.site.register(Participant, ParticipantAdmin) admin.site.register(Participant, ParticipantAdmin)
admin.site.register(Attribution, AttributionAdmin) admin.site.register(Attribution, AttributionAdmin)
admin.site.register(ChoixSpectacle, ChoixSpectacleAdmin) admin.site.register(ChoixSpectacle, ChoixSpectacleAdmin)
admin.site.register(Tirage, TirageAdmin) admin.site.register(Tirage, TirageAdmin)
admin.site.register(SpectacleRevente, SpectacleReventeAdmin)

View file

@ -5,6 +5,7 @@ from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
import calendar import calendar
import datetime
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -179,3 +180,25 @@ class Attribution(models.Model):
def __str__(self): def __str__(self):
return "%s -- %s" % (self.participant, self.spectacle) return "%s -- %s" % (self.participant, self.spectacle)
@python_2_unicode_compatible
class SpectacleRevente(models.Model):
attribution = models.OneToOneField(Attribution)
date = models.DateTimeField("Date de mise en vente",
default=timezone.now)
sold = models.BooleanField("Vendue", default=False)
def get_expiration_time(self):
remaining_time = (self.attribution.spectacle.date - self.date)
delay = max(datetime.timedelta(hours=2),
min(remaining_time/2, datetime.timedelta(days=2)))
return self.date + delay
expiration_time = property(get_expiration_time)
def get_shotgun(self):
return timezone.now > self.expiration_time
shotgun = property(get_shotgun)
def __str__(self):
return "%s" % self.attribution