Reputation: 137
I'm using the real django user.
In my project my user can create multiple warriors.
When I want to play I have to choose one of it.
So here is what my class looks like:
class Warrior:
nom = models.CharField(max_length=30, unique=True)
...
class Profile(models.Model):
user = models.OneToOneField(User)
warrior = models.ForeignKey(Warrior)
in my view, I want to change the actual warrior I'm playing with:
warrior = get_object_or_404(Warrior, id=id)
request.user.profile.warrior = warrior
But that code doesn't work. I think I have an error somewhere .
Upvotes: 0
Views: 1475
Reputation: 45575
request.user.profile.warrior = warrior
request.user.profile.save()
Upvotes: 2