How to take data from one model field to another in Django using fixture?

97 views Asked by At

I am using Django and i have two model: Jobs and Tit_suggestion. Both of them are like this :

class title_suggestion(models.Model):
    functional_area = models.ForeignKey(Jobs)
    job_title = models.CharField(max_length=255, blank=True, null=True)

and

class Jobs(models.Model):


    name = models.CharField(max_length=255, unique=True)
    short_name = models.CharField(max_length=255)

So , In Title_suggestion the field "job_title" contains data based on functional area id . and i have fixture file of this model.

Now i want to load same data in new field in jobs model using that fixture file. How to do this?? Please help me out. i am stuck here from last two days but could not find the relevant solution.

1

There are 1 answers

2
Brandon Taylor On

The short answer is you can't use a fixture from your title_suggestion model to populate your Jobs model because the structure is different.

In the title_suggestion fixture, job will be specified as the integer representing the primary key of the related job, not a complete object in JSON format.

Instead, you need to create as many Job instances in your fixture for jobs, then match up any foreign key instances in the title_suggestion fixture.