Note that there are some explanatory texts on larger screens.

plurals
  1. POWeekly-based populating a database with the django admin
    text
    copied!<p>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.</p> <p>I'm new to both python and django, and I'm using the django admin.</p> <p>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?).</p> <p>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?</p> <p><strong>Any</strong> kind of help will be great, I'm not asking to you people to make out my duty.</p> <p>Here is my models.py:</p> <pre><code>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 </code></pre> <p>And here is my admin.py</p> <pre><code>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 &lt;= 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) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload