Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5977981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:26:55+00:00 2026-05-22T21:26:55+00:00

I am creating an initializing file for for my django project database. I am

  • 0

I am creating an initializing file for for my django project database. I am doing this using a file called initial_data.json which i have created. For example the following code (when syncdb is run) creates in the model Word a new row where name="apple":

[ { "model": "sites.word", "pk": 1, "fields": { "name": "apple" } } ]

I have managed to this so far for several models, the problem is with models that have a many-to-many field. I’ve looked around for the correct way to do this and have come up empty.

So, for example, if a Model mood has many Interests how would I write in the Json file that mood-1’s interests are interest-1, interest-2 and interest-3.

What is the proper way to write in Json a models many-to-many relation?

EDIT:

@pastylegs solution was correct, I was just having trouble because the numbering of my interests was off in the Json file so it couldn’t match them with there moods.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:26:56+00:00Added an answer on May 22, 2026 at 9:26 pm

    I’m pretty sure the manytomany field of your model can be written like a simple list:

     [
        { 
            "model": "sites.word", 
            "pk": 1,
            "fields": { 
                "name": "apple",
                "my_m2m_field_name": [1,2,3],
            }
         }
    ]
    

    where 1, 2, 3 are the primary keys for the relations

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When creating a new project (universal iPhone/iPad) using Core Data, there's the usual appDelegate
I'm creating an app to show a book by using UIPageViewController (to have the
I am creating a project with Xcode 4.2 and using it's storyboard. In one
In a project I'm creating, I have various classes. One of my classes has
I have an ASP.NET application which tracks statistics by creating and writing to custom
A lot of Java ME tutorials use the startApp() method for creating and initializing
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
is declaring/initializing primitives the same as creating new objects? from what i know when
I'm creating a windows service program which invokes a java program. Here is part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.