- Why would I create a recursive relationship?
- Is this the same with the above?
aField = models.ForeignKey('self')
class aClass(models.Model):
aField = models.ForeignKey('aClass')
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You may need to create a recursive relationship when you would like to have parent and child nodes with identical model structure. For example if you have comments with text, data and user_id:
I think yes (you can try to test it) but it’s not a good form. If you change a class name then you must change the string value in brackets. If you use ‘self’ you haven’t this headache.