-1

I have a class Environment that has a list of Video objects (relationship One-To-Many), and in the class Video, i have a relationship with Environment of Many-To-One.

How to express this in Django?

Cœur
  • 37,241
  • 25
  • 195
  • 267
WitaloBenicio
  • 3,395
  • 5
  • 25
  • 32

2 Answers2

3

You need to set a foreign key in your model Video this

class Video(models.Model):
    environment = models.ForeignKey(Environment)
Alex Lord Mordor
  • 2,890
  • 7
  • 27
  • 47
1

You need to have a look of foreignkey in django

A foreign key is a many-to one relationship. In your example, one Environment can have many videos.

Community
  • 1
  • 1
Prashant Gaur
  • 9,540
  • 10
  • 49
  • 71