'how to return couple of variables in models.py [duplicate]

i need to return shop_nama nad adress to django site administration, here's the code

    shop_id = models.AutoField(primary_key=True, unique=True)
    shop_name = models.CharField(max_length=264)
    adress = models.TextField(max_length=264, default='')

    def __str__(self):
        return self.shop_name

but it shows error when i type return self.shop_name, self.adress error says: str returned non-string (type tuple)

sooo how to fix this problem?



Solution 1:[1]

Use F String in str function:

 def __str__(self):
        return f"{self.shop_name},{self.adress }"

Solution 2:[2]

That's because you can return only one string to the administration page in Django, which is the string you will read on it.

You need to concatanate strings

shop_id = models.AutoField(primary_key=True, unique=True)
shop_name = models.CharField(max_length=264)
adress = models.TextField(max_length=264, default='')

def __str__(self):
    return self.shop_name + ' ' + self.adress

(Assuming that self.adress is a string)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 enes islam
Solution 2 NicoCaldo