Django form linked to registration

Asked

Viewed 274 times

0

I have two tables in Django (Game and Goal) and I’m trying to create a form for them:

class Jogo(models.Model):
    ativo = models.BooleanField(default = True)
    dataHoraInicio = models.DateTimeField(verbose_name = 'Data e Hora de Início')
    dataHoraFim = models.DateTimeField(verbose_name = 'Data e Hora de Fim', null = True, blank = True)

class Gol(models.Model):
    jogo = models.ForeignKey(Jogo, on_delete = models.CASCADE)
    minuto = models.IntegerField(help_text = 'Minuto do jogo em que aconteceu o gol')
    jogador = models.CharField(max_length = 50)

My question is to link the form fields to the Gol table records so that, for each record, there are the 'minute' and 'player' fields, where the user can modify the table data.

How can I do that?

  • But what is your specific doubt? What have you tried? if you have never done anything with "linked to records" Forms in Jango, it is difficult to explain in a response, I suggest you do the documentation tutorial from the beginning, in part 4 is addressed the use of Forms.

  • Good afternoon friend. Normally the form fields are linked to the database table fields. What I am trying to do is link the form fields with the database records and not with the table fields. Another similar example: make a form with a checkbox for each user permission in the authentication part of Django. Get my point?

  • No, not necessarily the fields "are linked" to something, you are configuring it, linking, directly, something from the front end (in this case your form) to something from the back end (in this case the bank) is impossible in Jango, because it follows the MVC standard (called by some as MVT, because of the templates). I repeat, do not waste time, what you want this in the tutorial I indicated.

  • Thank you for answering, friend. I believe I did not express myself well. I know that it is possible to create forms directly, with no link to a database. I already know these most basic concepts and have analyzed this tutorial since version 1.6.5 of Django, when I started working with the framework in 2015. My doubt is at another specific point and maybe it’s in the documentation but I couldn’t find it.

  • What I want is to streamline the generation of the fields of a form based on the records of a database table, such as creating a series of checkboxes with the permissions of users in Django.contrib.auth or the example I had previously posted. Do you know any function of Django.forms.Form that can be rewritten and that is loaded when the form is rendered in the template, for example?

No answers

Browser other questions tagged

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