1
Good afternoon...I’m trying to make a filter through Foreignkey, return only items that are not included in the registry of allocations, I’m using Select2...but I can’t filter...
I have 3 models: class, class and Allocate
want to make allocations from them, and in pop up, I just want to appear items that have not been allocated yet
model allocation
class Alocar(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT)
data = models.DateField('Data', auto_now=True, blank=True)
turma = models.ForeignKey(Turma, on_delete=models.PROTECT)
sala = models.ForeignKey(Sala, on_delete=models.PROTECT)
criada = models.DateTimeField('Criada', auto_now_add=True)
alterada = models.DateTimeField('Alterada', auto_now=True)
model class
class Turma(models.Model):
turma = models.CharField('Código', max_length=8, unique=True)
curso = models.CharField('Curso', null=False, max_length=50)
periodo = models.CharField('Periodo', null=False, max_length=50)
disciplina = models.CharField('Disciplina', max_length=50)
qtdalunos = models.PositiveSmallIntegerField('Qtd')
professor = models.CharField('Professor', max_length=50)
alocada = models.BooleanField('Alocada', default=False)
internet = models.BooleanField('Internet', default=False)
projetor = models.BooleanField('Projetor', default=False)
computador = models.BooleanField('Computador', default=False)
criada = models.DateTimeField('Criada', auto_now_add=True)
alterada = models.DateTimeField('Alterada', auto_now=True)
model room
class Sala(models.Model):
bloco = models.ForeignKey(Bloco, on_delete=models.PROTECT)
sala = models.CharField('Sala', max_length=50, unique=True, help_text="Descrição")
capmaxima = models.PositiveSmallIntegerField('Cap. Máxima:')
disponivel = models.BooleanField('Disponivel', default=True)
internet = models.BooleanField('Internet', default=False)
projetor = models.BooleanField('Projetor', default=True)
computador = models.BooleanField('Computador', default=False)
criada = models.DateTimeField('Criada', auto_now_add=True)
alterada = models.DateTimeField('Alterada ', auto_now=True)
form
from django_select2 import forms as s2forms
import select2.fields
import select2.models
from django_select2.forms import Select2Widget
class AddAlocForm(forms.ModelForm):
class Meta:
model = Alocar
fields = ('turma','sala','dia','horario')
widgets = {
'turma': Select2Widget,
'sala': Select2Widget,
'dia': Select2Widget,
'horario': Select2Widget,
}
note the pop up, the featured item, is not to appear in the list,
If the items were not registered the data describing them exist where? Maybe you should rephrase your question.
– anonimo
Thanks, buddy... I took your advice and added more code...
– ElvisDba
How a room is allocated?
– Italo Lemos
@Italo Lemos Good evening...on model allocatar.. there is the foreign key, the class and the room......
– ElvisDba