Hello, I am trying to create test for my app
in the model.py I have this
class Marketplaces(models.Model):
name = models.CharField(max_length=60, unique=True)
group_id = models.ForeignKey(Group, on_delete=models.CASCADE)
So to create an object in my test I need to give a group
def test_marketplaces(self):
groupTest2 = Group.objects.create(name='GroupTest2')
userTest2 = User.objects.create_user(username="UserTest2")
groupTest2.user_set.add(userTest2)
marketplace = Marketplaces.objects.create(name='Market',
group_id=userTest2.groups.all().first().id)
But when I do this or I use group_id=groupTest2.pk
I get the error : ValueError: Cannot assign â3â: âMarketplaces.group_idâ must be a âGroupâ instance.
I donât understand the error. How am I supposed to write it correctly?