Last active
April 11, 2020 16:51
-
-
Save bismarck4lves/3258e345482dc13b2001af29a5aa2108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" MODEL """ | |
class Agendas (models.Model): | |
id = models.AutoField(primary_key=True) | |
pessoa = models.ForeignKey( | |
Medicos, related_name='Medicos', on_delete=models.CASCADE) | |
dia = models.DateField() | |
horario = models.ManyToManyField('Horas') | |
class Meta: | |
verbose_name_plural = "Agendas" | |
unique_together = ('dia', 'pessoa',) | |
ordering = ['dia'] | |
def __str__(self): | |
return self.medico | |
""" FORM """ | |
class AgendaForm(forms.ModelForm): | |
class Meta: | |
model = Agendas | |
fields = ['dia', 'medico'] | |
def clean(self): | |
dia = self.cleaned_data["dia"] | |
if dia < date.today(): | |
raise forms.ValidationError( | |
'Consultas não podem ser marcadas para datas passadas.') | |
return self.cleaned_data | |
""" ADMIN """ | |
não mostra horarios | |
@admin.register(Agendas) | |
class AgendasAdmin (admin.ModelAdmin): | |
form = AgendaForm | |
list_display = ['id', 'pessoa', 'dia'] | |
mostra horarios | |
admin.site.register(Agendas) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment