In Django, how do you make a model refer to itself?

前端 未结 4 1988
耶瑟儿~
耶瑟儿~ 2020-12-15 15:49

Assume we have class Employee. I want to have a field which references a different instance of the same class.

How to write this? How about the followi

4条回答
  •  醉酒成梦
    2020-12-15 16:22

    A constraint forcing id and ref_employee_id to have separate values is outside the scope of Django's ORM. You will need to add said constraint at the database level, via SQL in syncdb or manually.

提交回复
热议问题