A
A
Ali Kasimova2021-04-25 19:50:59
Django
Ali Kasimova, 2021-04-25 19:50:59

Issue with ForeignKey List in Django ModelForm?

I have a list of employees.

models.py:

class NumberOfMealsEaten(models.Model):
    month = models.ForeignKey(Months, on_delete=models.CASCADE)
    staff = models.ForeignKey(Staffs, on_delete=models.CASCADE)
    maelseaten = models.IntegerField("Number of meals eaten", validators=[MinValueValidator(0)], default=0)

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


For these employees, meal fees are calculated each month based on how many meals each employee ate.

First, at the beginning, I want to select "relevant month name" only once. I then want the employee names from Foreignkey to automatically be listed as "text" in the template, not as a drop down menu. So I just want the "maelseaten" field to be filled in for staff.

As an example, the list would look like this:

60859d2801a4b514415893.png

In other words, this form will add the number of meals for each employee for the selected month to the database.

Thank you in advance for your attention and help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question