0

Newly created user have some initial data. -- This feature really I want.

Tried.

I put some sample values into table( FamilyMember ) and dumped into json format and put that into the name of initial_data.json in fixtures directory.

Above working fine when i put below lines in command prompt.

python manage.py loaddata --app dashboard initial_data.json

But in my case every registered user will get this data instantly they logged in. How do i gonna achieve this ?

Sample json:

[  
    {  
        "fields":{  
            "first_name":"Father",
            "last_name":"Father",
            "middle_name":"",
            "birth_state":"",
            "wife":[  

            ],
            "member_image":"",
            "familyname":1,
            "children":[  
                9
            ],
            "sex":"M",
            "preferred_name":"",
            "parents":[  

            ],
            "birth_country":"",
            "birth_date":"1988-11-10",
            "bio_info":"Hi Some Info Here",
            "birth_city":"Country"
        },
        "model":"dashboard.familymember",
        "pk":6
    },
]
  • How about adding a default value directly into your model? – Sachi Tekina Mar 30 '15 at 08:50
  • Me too thought about that idea because manytomany relation with fixture really gonna hard. Can you provide me some of example how to go with it ? –  Mar 30 '15 at 08:54

1 Answers1

2

You can check this link: Default value for field in Django model. Why do you have a pk attribute? Django automatically creates an id.

class FamilyMember(models.Model):
    user = models.OneToOneField(User)
    birth_city = models.CharField(max_length=100, default='Country', editable=False)
    ....
Community
  • 1
  • 1
Sachi Tekina
  • 1,800
  • 5
  • 28
  • 50
  • Instead of `OnetoOneField`, use `ManytoManyField`. Replace `User` to the class that you want to have a relationship with. – Sachi Tekina Mar 30 '15 at 09:25