Django Modelform ForeignKey Listing Problem

Submitted 3 years ago
Ticket #419
Views 430
Language/Framework Django
Priority Medium
Status In-Progress

I have a staff list. I have a model for this as follows.

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, the meal fee is calculated every month according to how many meals each staff has eaten.

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

As an example, the list will look like this:

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

Thank you in advance for your attention and help.

Submitted on Apr 25, 21

can we connect and discuss about this? - Vengat 3 years ago

I am not sure what is the exact requirement. Looks like its just FK relationship design. If still an issue let me know we can connect so that i could able to provide more details if i know - Vengat 3 years ago
add a comment

Latest Blogs