Sorry - it should read:
b = Book.objects.get(id=1) #new book
request.user.get_profile().shelf1.add(b) #add book to shelf1
request.user.get_profile().shelf1.remove(b)#remove from shelf1
request.user.get_profile().shelf2.add(b) #add to shelf2
I
> b = Book.objects.get(id=1) #new book
> request.user.get_profile().shelf1.add(b) #add book to shelf1
> request.user.shelf1.remove(b) #remove from shelf1
> request.user.shelf2.add(b) #add to shelf2
Looks like you're trying to add the foreignkey to the User model
instead of the
Hi - I'm having a hard time wrapping my head around one-to-many
relations. I'd like to be able to do this in a view:
b = Book.objects.get(id=1) #new book
request.user.get_profile().shelf1.add(b) #add book to shelf1
request.user.shelf1.remove(b) #remove from shelf1
3 matches
Mail list logo