Sorry if my question turns out to be stupid, but I'm pretty new to Django and I couldn't find the answer anywhere.
I have the following model:
class BlackListEntry(models.Model): user_banned = models.ForeignKey(auth.models.User,related_name="user_banned") user_banning = models.ForeignKey(auth.models.User,related_name="user_banning")
Now when I try to create an object like this:
BlackListEntry.objects.create(user_banned=int(user_id),user_banning=int(banning_id))
I get the following error:
Cannot assign "1": "BlackListEntry.user_banned" must be a "User" instance.
Of course, if I replaced it with something like this:
user_banned = User.objects.get(pk=user_id) user_banning = User.objects.get(pk=banning_id) BlackListEntry.objects.create(user_banned=user_banned,user_banning=user_banning)
everything is working fine. The question arises:
Is my solution getting into the database to retrieve both users, and if so, can this be avoided just by passing identifiers?
python django django-models
Marcin kulus
source share