How to convert field values of a model into field names of a new one (model) in DJANGO 4?

I’m building models for a project in DJANGO 4, but I got stuck when it came to CONVERTING FIELD VALUES OF AN EXISTING MODEL INTO THE FIELD NAMES OF A NEW ONE (MODEL).

As may be seen from the image I do attach, I have MODEL A with ‘fieldName_3’. I’d appreciate a help to convert the values of this field into the field names of the MODEL B.

Descriptive Image
New Picture
I want to turn the values P1, P2 and P3 (red colored) in Model_A into fields P1, P2 and P3 (also red colored) in Model_B.


from django.db import models

CHOICES = (('option1','option1'),('option2','option2'))

class Model_A(models.Model):
fieldName_1 = models.CharField(max_length=50)
fieldName_2 = models.CharField(max_length=20)
fieldName_3 = models.CharField(max_length=3)

class Model_B(models.Model):
    def values_from_fildName3():
        values = Model_A.fieldName_3
        for value in values:
            value = models.CharField(max_length=4, choices=CHOICES)
            yield value

With the code above I get the error "TypeError: ‘DeferredAttribute’ object is not iterable

My advancing thanks!

Side note: When posting code, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted

The Django models are Python classes. This means that you can use the Python getattr and setattr functions to reference fields by name.

Thank you very much for the hint, I’ll take it into considerations.