0
class Comment(models.Model):

user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='st_comments')

I have the above class in models.py .

related_name

has the backward relationship to what? st_comments?

What exactly is st_comments and where is it located and how is it related? Is it a field entry in another class?

If you need more info please check this

I've been through this and this

Community
  • 1
  • 1
n00b
  • 209
  • 1
  • 15
  • 1
    Rather than looking at other questions, did you [read the official documentation](https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey.related_name)? What is unclear? – Daniel Roseman Sep 16 '15 at 10:06
  • I already read this. https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey.related_name – n00b Sep 16 '15 at 10:17
  • OK, so what's not clear? – Daniel Roseman Sep 16 '15 at 10:18
  • from the official docs. related_name="tags" Where is "tags" located? – n00b Sep 16 '15 at 10:20
  • I'm sorry I really don't understand what you're asking here. The [other doc page](https://docs.djangoproject.com/en/1.8/topics/db/queries/#backwards-related-objects) you linked to showed **exactly** where it is used. Why is this confusing? – Daniel Roseman Sep 16 '15 at 10:28
  • I searched the models.py file and other related files for 'st_comments' , as it is backward related. It must be somewhere in other models. But there's nowhere in the entire app st_comments is mentioned. So what's it doing? Thank you so much sir. Hope this is helpful – n00b Sep 16 '15 at 10:37
  • No, it is *defined in the code you've given*. That is where it is defined. Why would it be anywhere else? – Daniel Roseman Sep 16 '15 at 10:40
  • 2
    It won't appear in your code anywhere, it is field added by django on runtime into another model, so you can access your relation in reversed direction - from related model. – GwynBleidD Sep 16 '15 at 10:41

1 Answers1

2

st_comments will be located inside User model (or other model provided in settings.AUTH_USER_MODEL) and it will contain queryset to all comments assigned to particular user.

GwynBleidD
  • 20,081
  • 5
  • 46
  • 77