A
A
Alexander Proshchenkov2018-05-26 15:07:20
Django
Alexander Proshchenkov, 2018-05-26 15:07:20

How to write a model for django?

How to write a django model? About the task: There is a list of people, let's say 10 people. Every day you will need to mark each person with a conditional plus sign. Here's how I tried to do it:

class people(models.Model):
  date = models.DateField("Дата")
  a = models.CharField("Александр Иванов", max_length=1)
  b = models.CharField("Алексей Иванов", max_length=1)
  c = models.CharField("Даниил Иванов", max_length=1)

Is it possible to optimize somehow, because c = models.CharField("Daniil Ivanov", max_length=1) such a construction looks terrible
+ This table should look like a visual table

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2018-05-26
@Keltor

This is how your models should look like:

class People(models.Model):
    first_name = models.CharField("Имя", max_length=64)
    last_name = models.CharField("Фамилия", max_length=64)

    def __str__(self):
          return '{} {}'.format(self.first_name, self.last_name)


class PeoplePresence(models.Model):
     date = models.DateField()
     people = models.ManyToManyField(People)

     def __str__(self):
          return '{} {}'.format(self.date, self.people.__str__())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question