django get all model fields

from django.db import models

class YourModel(models.Model):
    field1 = models.CharField(max_length=255)
    field2 = models.IntegerField()
    field3 = models.DateField()
    # Add more fields as needed

# Get all model fields
all_fields = YourModel._meta.get_fields()

# Iterate through fields and print information
for field in all_fields:
    print(f"Field Name: {field.name}")
    print(f"Field Type: {field.get_internal_type()}")
    print(f"Is Primary Key: {field.primary_key}")
    print(f"Is Required: {not field.blank}")
    print(f"Is Nullable: {field.null}")
    print(f"Is Auto Increment: {field.auto_created}")
    print(f"Is Unique: {field.unique}")
    print("------")

This code retrieves all fields of a Django model, iterates through them, and prints information about each field, including the field name, type, whether it's a primary key, whether it's required, nullable, auto-incremented, and unique.