I have model Product where as primary key use code field which is UUID. I want take list of ids of all products.
I want list like this:
['14431ec4-3224-480f-85e2-b541891919b1', '6e54636b-7283-4504-a16f-f54d29db26f2']
I tried next code but it return me this:
[UUID('14431ec4-3224-480f-85e2-b541891919b1'), UUID('6e54636b-7283-4504-a16f-f54d29db26f2')]
models.py:
class Product(models.Model):
code = models.UUIDField(_('Code'), primary_key=True, default=uuid.uuid4, editable=False)
views.py:
products = Product.objects.all()
product_ids = []
for product in products:
product_ids.append(product.code)
print(product_ids)
How to fix this problem?