(Django) Send form to another table

Asked

Viewed 66 times

0

I’m a beginner in Django and I’m picking up a lot on one thing. I want to submit a form that has already been filled out for another table. I need somehow to select which table the form will be sent, and that it "go" with all the data that has already been inserted later.

Every time a new form is created, it goes to the home page:FormularioNote that the information has already been entered. I want to take the same information, select the Model Class, and send to the selected one.

I plan to make a kind of pendencia system to send to other people/ sectors.

My Models.py:

from django.db import models
from django.contrib.auth.models import User

class Solicitacao(models.Model):
  nome = models.CharField(max_length=100)
  carteira = models.CharField(max_length=17)
  atendimento = models.CharField(max_length=100)
  descricao = models.TextField()
  data_da_solicitacao = models.DateTimeField(auto_now_add=True)
  active = models.BooleanField(default=True)
  user = models.ForeignKey(User, on_delete=models.CASCADE)
  email = models.EmailField(null=True, blank=True)
  telefone = models.CharField(max_length=100, null=True, blank=True)
  arquivo = models.FileField(upload_to='documentos/%y/%m/%d/', null=True, blank=True)


  def __str__(self):
     return str(self.id)

  class Sala1(models.Model):
     nome = models.CharField(max_length=100)
     carteira = models.CharField(max_length=17)
     atendimento = models.CharField(max_length=100)
     descricao = models.TextField()
     data_da_solicitacao = models.DateTimeField(auto_now_add=True)
     active = models.BooleanField(default=True)
     user = models.ForeignKey(User, on_delete=models.CASCADE)
     documentos = models.FileField(null=True, blank=True)
     email = models.EmailField(null=True, blank=True)
     telefone = models.CharField(max_length=100, null=True, blank=True)
     arquivo = models.FileField(upload_to='documentos/%y/%m/%d/', null=True, blank=True)

     def __str__(self):
        return str(self.id)

     class Sala2(models.Model):
        nome = models.CharField(max_length=100)
        carteira = models.CharField(max_length=17)
        atendimento = models.CharField(max_length=100)
        descricao = models.TextField()
        data_da_solicitacao = models.DateTimeField(auto_now_add=True)
        active = models.BooleanField(default=True)
        user = models.ForeignKey(User, on_delete=models.CASCADE)
        documentos = models.FileField(null=True, blank=True)
        email = models.EmailField(null=True, blank=True)
        telefone = models.CharField(max_length=100, null=True, blank=True)
        arquivo = models.FileField(upload_to='documentos/%y/%m/%d/', null=True, blank=True)

        def __str__(self):
          return str(self.id)

     class Sala3(models.Model):
         nome = models.CharField(max_length=100)
         carteira = models.CharField(max_length=17)
         atendimento = models.CharField(max_length=100)
         descricao = models.TextField()
         data_da_solicitacao = models.DateTimeField(auto_now_add=True)
         active = models.BooleanField(default=True)
         user = models.ForeignKey(User, on_delete=models.CASCADE)
         documentos = models.FileField(null=True, blank=True)
         email = models.EmailField(null=True, blank=True)
         telefone = models.CharField(max_length=100, null=True, blank=True)
         arquivo = models.FileField(upload_to='documentos/%y/%m/%d/', null=True, blank=True)

         def __str__(self):
             return str(self.id)

View.py: In the view I have no idea what to make it work.

1 answer

0

I see no sense in the implementation of the Sala1, Sala2 and Sala3 classes, which is the same model as the Request class. I didn’t quite understand the purpose of your system, but regardless of that, having more than one table with exactly the same structure, besides not making sense, does not seem to me to be a good practice for your project.

E.g.: If each registered request is linked to a room, you can create a Room app, create the corresponding Model, and in the request create a Foreignkey type field.

The data will be recorded in the table corresponding to the Model used in the View. For example, if you create a View for request registration, you will load the Request Model into your View, and then implement the code to perform the registration. This View will be called by the URL you register. In your form, you will make a POST to the address set in url.py. The url in question will call the corresponding View. The same goes for editing, deletion, listing and whatever else you need to implement.

A sequence of videos I consumed when I was at the beginning is this one: https://www.youtube.com/watch?v=UIvnNCQnejw&list=PLHWfNMxB2F4HdKbo8zdgXyxVDOxH429Ko

I believe you can resolve your initial doubts.

Hugs,

Browser other questions tagged

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