I am reading a book called 'Packt Publishing, Learning Website Development with Django' and I am doing a tutorial on how to create a bookmarking website where users can read articles and bookmark them / save the url to the article. Here is the models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Link(models.Model):
url = models.URLField(unique=True)
class Bookmark(models.Model):
title = models.CharField(max_length=200)
user = models.ForeignKey(User)
link = models.ForeignKey(Link)
Now, this is my user_page view (where the username is passed as a parameter to the view)
def user_page(request, username):
try:
user = User.objects.get(uesrname=username)
except:
raise Http404('Requested user not found.')
bookmarks = user.bookmark_set.all()
variables = {
'username': username,
'bookmarks': bookmarks
}
return render(request, 'user_page.html', variables)
I'm confused about the line
bookmarks = user.bookmark_set.all()
I understand that 'user' is a user object, but we are using the generic User model provided by Django, which only has username, password and email, right? So where is bookmark_set coming from? Because if it is trying to access all bookmarks from the bookmark class, shouldn't the 'b' in bookmark_set at least be upper case? and what does the _set do? In the book, it explains this line by saying
"To obtain the list of bookmarks for a particular user object, we can
conveniently use the bookmark_set attribute available in the user object"
I tried google'ing all the attributes available for the user object but couldn't find anything. Is there a website which has a list of all the attributes available for the user object?