Django Modelform ForeignKey Listing Problem

Submitted 1 year, 5 months ago
Ticket #419
Views 231
Language 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 1 year, 5 months 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 1 year, 5 months ago
add a comment

Wanna Post Ad?
Reach a large group of audience by posting an ad about your business here. For more details
Drop us a Message