Найти - Пользователи
Полная версия: reference to same model
Начало » Django » reference to same model
1
crchemist
Привіт. Хочу зробити шось таке:
class Lesson(models.Model):
"""Lesson objects are organized in double-linked list.
"""
text = models.TextField()

next_l = models.ForeignKey(Lesson)
prev_l = models.ForeignKey(Lesson)
Але воно в мене видає:
    next_l = models.ForeignKey(Lesson)
NameError: name 'Lesson' is not defined
Як можна зробити шось подібне в джанго?
Александр Кошелев
http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey
To create a recursive relationship – an object that has a many-to-one relationship with itself – use models.ForeignKey('self').
romankrv
crchemist
Як можна зробити шось подібне в джанго?
Так ты уже сделал это в джанго коде определил модель правда модель не будет работать как ты написал.
дальше напиши что ты хочешь сделать с моделью
тебе надо что то типа этого тогда написать:

next_l = models.ForeignKey('self', blank=True, null=True)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB