I have model Topic. Now i have date = models.DateTimeField
class Topic(models.Model):
owner = models.ForeignKey(Profile, on_delete=models.SET(GUEST_ID))
seminar = models.ForeignKey(Seminar, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
description = models.TextField(default='')
speaker_name = models.CharField(max_length=200, default='')
date = models.DateTimeField(null=True, blank=True)
but i want to save multiple date for example: 27.11.2022,29.11.2022,01.01.2023. I have idea to write
date = models.CharField()
and save dates as string
Is there a better solution?
CodePudding user response:
Using JsonField
would give you a good flexibility to store unstructured data.
For example:
class Topic(models.Model):
...
dates = models.JsonField(null=True, blank=True)
Then you can save your dates like:
{
"date_title_one": "some_data",
"date_title_two": "some_data_2"
}
Read about JsonField