我想创建一个旅游应用程序,其中包括“旅游”和“景点”,“旅游”模式将有多个“兴趣地点”。一个“景点”应该可以添加到多个“旅游”。
到目前为止,我只能在一次“游览”中添加一个“名胜古迹”。
这是我的模型:
class PlaceOfInterest(models.Model):
name = models.CharField(max_length=255)
tour = models.ForeignKey("Tour", on_delete=models.CASCADE, related_name="tours", blank=True, null=True)
class Tour(models.Model):
title = models.CharField(max_length=255)代表这种情况的最佳方式是什么?
发布于 2021-12-12 15:50:13
要解决这个问题,您可以定义一个多对多关系--从Tour到PlaceOfInterest
试试看
class PlaceOfInterest(models.Model):
name = models.CharField(max_length=255)
class Tour(models.Model):
title = models.CharField(max_length=255)
tour = models.ManyToManyField("PlaceOfInterest", related_name="tour_poi", blank=True, null=True)https://stackoverflow.com/questions/70324999
复制相似问题