0

Actually, this question has puzzled me for a long time.

Say, I have two models, Course and CourseDate, as follows:

class Course(models.Model):
    name = model.CharField()

class CourseDate(models.Model):
    course = modelds.ForienKey(Course)
    date = models.DateField()

where CourseDate is the dates that a certain course will take place.

I could also define Course as follows and discard CourseDate:

class Course(models.Model):
    name = models.CharField()
    dates = models.CharField()

where the dates field contains dates represented by strings. For example:

dates = '2016-10-1,2016-10-12,2016-10-30'

I don't know if the second solution is kind of "cheating". So, which one is better?

Randy Tang
  • 4,283
  • 12
  • 54
  • 112
  • 2
    http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad/3653574 – e4c5 Oct 07 '16 at 08:01

1 Answers1

2

I don't know about cheating, but it certainly goes against good database design. More to the point, it prevents you from doing almost all kinds of useful queries on that field. What if you wanted to know all courses that had dates within two days of a specific date? Almost impossible to do that with solution 2, but simple with solution 1.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895