Created
April 11, 2020 22:24
-
-
Save bismarck4lves/359ec8935f5b39895f382fc47b1eb276 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
""" MODELS """ | |
class Horas (models.Model): | |
id = models.AutoField(primary_key=True) | |
hora = models.TimeField() | |
status = models.BooleanField(default=True) | |
class Meta: | |
verbose_name_plural = "Horas" | |
def __str__(self): | |
return str(self.hora) | |
class Agendas (models.Model): | |
id = models.AutoField(primary_key=True) | |
pessoa = models.ForeignKey( | |
Pessoas, related_name='Medicos', on_delete=models.CASCADE) | |
dia = models.DateField() | |
horario = models.ManyToManyField('Horas') | |
class Meta: | |
verbose_name_plural = "Agendas" | |
unique_together = ('dia', 'pessoas',) | |
ordering = ['dia'] | |
def __str__(self): | |
return str(self.dia) | |
""" VIEWSET """ | |
queryset = Agendas.objects.annotate( | |
data_hora=Concat('dia', models.Value(' '), 'horario__hora'), output_field=models.DateTimeField()) | |
agenda = queryset.filter(data_hora__gte=datetime.today()) | |
""" ERRO """ | |
TypeError at /agendas/ | |
QuerySet.annotate() received non-expression(s): <django.db.models.fields.DateTimeField>. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment