Django设计应用与体育课。

时间:2021-10-12 19:33:27

I would like to desing web application in django to make reservations for gym classes. I have some problems desiging it, because I don't know how usually such problems are solved.

So one gym class takes place once a week, f.e. monday at 19.00 and only 20 people can attend it. Reservation should be possible one week before, so if class takes place 28 May at 19.00, reservation should be possible since 21 May 00:00.

And now some questions:
1. One class should be one object in a model (one record), right? But should it be one kind of class (so class that takes place every monday is one record) or class that occurs at specific date (so one class in one week is one record, after 3 weeks, we have 3 records of this class)?
2. How to create these records? Should I make automatic copy of today's classes, changing date to +1 week? How to solve these problems?

我想在django开发一个web应用程序来预订健身房的课程。我设计它有一些问题,因为我不知道这些问题通常是如何解决的。所以一个体育课每周一次,周一在19点,只有20个人可以参加。预订应在一周之前预订,所以如果上课时间是5月28日,那么预订应该在5月21日开始。现在有几个问题:1。一个类应该是模型中的一个对象(一条记录),对吗?但是它应该是一种课程(每周一的课程是一个记录)还是在特定的日期发生的课程(所以一周的一节课是一个记录,3周后,我们有这门课的3条记录)?2。如何创建这些记录?我应该自动复制今天的课程,把日期改为+1周吗?如何解决这些问题?

1 个解决方案

#1


1  

Well, you can create, f.e. a model that will represent a current timetable (schedule) for a gym class and another model that will represent a particular record for some day.

嗯,你可以创建一个模型,f.e.e,它将代表一个体育课的当前时间表(时间表),另一个模型将代表某一天的特定记录。

For example smth like that:

比如像这样的smth:

class ClassType(models.Model):
    name = models.CharField(u"Class name", max_length = 120)
    schedule_day = models.IntegerField(u"Day of week")
    schedule_time = models.TimeField(u"Time")
    max_attend = models.IntegerField(u"Maximum attendants")

class ClassRecord(models.Model):
    type = models.ForeignKey(ClassType, verbose_name = "Class type")
    date = models.DateTime("Scheduled date")
    attendants = models.ManyToManyField(User) #don't forget to import it

So, you can specify a schedule and class types if they will change in the future. You can create a command (see manage.py commands in django documentation) that will create a ClassRecord for the next week and set this command on cron (or celery for example), so it will run once a week and create new records when needed.

因此,如果将来计划和类类型发生变化,您可以指定它们。您可以创建一个命令(参见管理)。在django文档中,py命令将为下一周创建一个ClassRecord,并将这个命令设置为cron(例如,比如西芹),因此它将在一周运行一次,并在需要时创建新记录。

#1


1  

Well, you can create, f.e. a model that will represent a current timetable (schedule) for a gym class and another model that will represent a particular record for some day.

嗯,你可以创建一个模型,f.e.e,它将代表一个体育课的当前时间表(时间表),另一个模型将代表某一天的特定记录。

For example smth like that:

比如像这样的smth:

class ClassType(models.Model):
    name = models.CharField(u"Class name", max_length = 120)
    schedule_day = models.IntegerField(u"Day of week")
    schedule_time = models.TimeField(u"Time")
    max_attend = models.IntegerField(u"Maximum attendants")

class ClassRecord(models.Model):
    type = models.ForeignKey(ClassType, verbose_name = "Class type")
    date = models.DateTime("Scheduled date")
    attendants = models.ManyToManyField(User) #don't forget to import it

So, you can specify a schedule and class types if they will change in the future. You can create a command (see manage.py commands in django documentation) that will create a ClassRecord for the next week and set this command on cron (or celery for example), so it will run once a week and create new records when needed.

因此,如果将来计划和类类型发生变化,您可以指定它们。您可以创建一个命令(参见管理)。在django文档中,py命令将为下一周创建一个ClassRecord,并将这个命令设置为cron(例如,比如西芹),因此它将在一周运行一次,并在需要时创建新记录。