4

I create a site in Django and here is my Question How to make something like this:

On init (for example, when someone run "syncdb"?) I need to create a group with permissions and extend superuser profile from User to UserProfile(when user register it's not a problem but first admin/superuser is autocreated when app is created)

because, after installation you need to manually perform these operations in the admin panel.

sorry for my English, it's hard to explain to me the problem. I hope you understand.

Kubas
  • 976
  • 1
  • 15
  • 34

3 Answers3

6

2 steps:

  1. Take a dump from an existing database containing all the required data using the command dumpdata
  2. After syncdb, load the fixture using the command loaddata
shanyu
  • 9,536
  • 7
  • 60
  • 68
2

Hook the post_syncdb signal in your management subpackage and do the work there.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • The [docs](https://docs.djangoproject.com/en/1.4/ref/signals/#post-syncdb) say not to do anything that requires changing the db: "It is important that handlers of this signal perform idempotent changes (e.g. no database alterations) as this may cause the flush management command to fail if it also ran during the syncdb command." So adding a UserProfile or creating Groups is forbidden. – Carl G Jun 19 '12 at 18:29
1

I guess fixtures can help you out with your problem, check out these docs

Ashique PS
  • 691
  • 1
  • 12
  • 26
fijter
  • 17,607
  • 2
  • 25
  • 28