I'm building an small django app in order to manage a store employees roster. The employees are freelancers-like, they have weekly almost-fixed schedules, and may ask for extra ones at any weekday/time.
I'm new to both python and django, and I'm using the django admin.
Everything works fair enough (for me) when I "manually" add a "Turno" (work assignment, I'm not sure, it probably would be "Shift" in English?).
I need some way of adding the weekly fixed Turnos (all at once, and not "manually" one by one) through the django admin, say setting a weekday, the begining and ending times, and a stop date two (or three) months in advance ... How?
Any kind of help will be great, I'm not asking to you people to make out my duty.
Here is my models.py:
from django.db import models
from django.contrib.auth.models import User
import datetime
class Dia(models.Model):
fecha = models.DateField(unique=True)
class Meta:
ordering = ['fecha']
def __unicode__(self):
return (self.fecha.strftime('%A %d de %b de \'%y'))
class Turno(models.Model):
dia = models.ForeignKey(Dia)
perfil_usuario = models.ForeignKey(User, verbose_name="Usuario")
comienza = models.TimeField()
finaliza = models.TimeField()
comentarios = models.TextField(blank=True, null=True)
def __unicode__(self):
return self.dia.fecha.strftime('%A %d de %b de \'%y') + ' - ' + self.perfil_usuario.username
And here is my admin.py
from roquen.horarios.models import Turno, Dia
from django.contrib.auth.models import User
from django.contrib import admin
from django import forms
admin.site.register(Dia)
class TurnoAdminForm(forms.ModelForm):
class Meta:
model = Turno
def clean_finaliza(self):
data = self.cleaned_data['finaliza']
if data <= self.cleaned_data['comienza']:
raise forms.ValidationError('La hora de fin debe ser posterior a la de comienzo')
return data
class TurnoAdmin(admin.ModelAdmin):
form = TurnoAdminForm
list_display = ['dia', 'perfil_usuario', 'comienza', 'finaliza']
admin.site.register(Turno, TurnoAdmin)