django only certain columns from database

# 1. Import necessary modules and classes
from django.db import models

# 2. Define your model
class YourModel(models.Model):
    # Define all fields in your model
    field1 = models.CharField(max_length=100)
    field2 = models.IntegerField()
    field3 = models.DateTimeField()
    # Add more fields as needed

# 3. Create a migration for the model
# Run 'python manage.py makemigrations' in the terminal

# 4. Apply the migration
# Run 'python manage.py migrate' in the terminal

# 5. Query only specific columns from the database
# For example, to retrieve only 'field1' and 'field2' columns
result = YourModel.objects.values('field1', 'field2')

# 6. Iterate through the queryset and access the values
for entry in result:
    field1_value = entry['field1']
    field2_value = entry['field2']
    # Access more fields if needed

# Note: Replace 'YourModel' with the actual name of your Django model.