Multiple models - three apps

Asked

Viewed 52 times

-1

Good evening dear... my TCC project, has three apps: classrooms, classrooms and allocate. I need to make class allocations in the rooms, after allocated I need to schedule a class boleano as allocated, and a class boleano as unavailable. below send the code to be better elucidated. how should I implement this? I am stuck at this point, I confess that I am inexperienced with Django.

app rooms

class Sala(models.Model):
    bloco = models.ForeignKey(Bloco, on_delete=models.PROTECT)
    sala = models.CharField('Sala: ', unique=True, max_length=50)
    capmaxima = models.IntegerField('Cap. Máxima: ')
    disponivel = models.BooleanField('Disponivel', default=True)
    ocupada = models.BooleanField('Ocupada', default=False)
    internet = models.BooleanField('Internet', default=False)
    projetor = models.BooleanField('Projetor', default=True)
    computador = models.BooleanField('Computador', default=False)

app classes

class Turma(models.Model):
    turma = models.CharField('Turma', max_length=20)
    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.IntegerField('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)

allocate

class Alocar(models.Model):
    data = models.DateField('Data', auto_now=True, blank=True)
    dias = [
        ('A Confirmar', 'A Confirmar'),
        ('Segunda', 'Segunda'),
        ('Terça', 'Terça'),
        ('Quarta', 'Quarta'),
        ('Quinta', 'Quinta'),
        ('Sexta', 'Sexta'),
        ('Sábado', 'Sábado'),
    ]
    dia = models.CharField('Dia', max_length=11, choices=dias, 
    default='A Confirmar')
    horario = models.ForeignKey(Horario, on_delete=models.CASCADE)
    turma = models.ForeignKey(Turma, on_delete=models.SET())
    sala = models.ForeignKey(Sala, on_delete=models.SET())

Thank you for your attention.

  • You seem to be mixing the concepts a little bit here. Django has the concept of App, but is not the model or object (database table), but something more comprehensive, "App in Django and one of the great responsible for its flexibility and high reuse of components". Regarding your questions. Explain a little better what you want to do, will you create a Web App with Django’s Amin feature? What code have you done to achieve this goal? Your models.py’s classes are not enough.

  • Good evening...what is preventing my advancement is that I need to allocate a class in a room, after allocated have to show that the room is unavailable and the class is allocated, the Fields are boleanos...I believe that this should be done in the save_model method in admin.py, however I do not know how to start ...the models' codes are the ones that are just above, the model allocate has two foreign keys, class and room.... when I say apps are in the same project, same directory

  • Viva, I share an answer to some questions I took a few days ago (https://answall.com/questions/437747/como-fazer-esse-typo-relationship-no-django/438675#438675), you already have the admin.py file, add based on this example to have access in admin, don’t forget that admin is inactive by default, you have to uncomment a line in Settings.py and 2/3 in urls.py. When you have the admin active, in practice you do not need to define any save, the framework already makes CRUD available for you, only in special case, but in time.

  • Friend good night...I realized that Voce has knowledge of the subject...I did another post, with the following title "Delete without error"...I’m running out of time to deliver my TCC... if possible help me a lot thanks..

  • Hi, I’ve been working with Django for a long time. In fact, when posts are about academic work, I don’t know if I should help, I’m always reticent, especially when there’s no visible research effort, And on the other hand, because I’m helping people who are learning, I may be taking part of this individual learning, which is research, reading documentation, etc. You know? Another question, if in this question you have the solution, share in an answer (after your TCC is over), and so you can help others, will be a little the spirit of this platform.

1 answer

0

Just you set available to False when making an allocation

This was done in the view, inside the method you create when set the dates, which class is you go there and change the boolean value:

def alocar_view(request):
  ...
  ...
  turma.alocada = True
  sala.disponivel = False
  • #this is my form class Meta: model = Allocate Fields = ['class','room','day','time'] ##this is my view form = Addalocfom(request.POST or None) form.is_valid(): form.sala.available = False form.turma.allocated = True form.save() form = Addalocfom() #gave this error Attributeerror at /addaloc 'Addalocfom' Object has no attribute 'room'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.