So much for a post title.

The thing is as follows:

  1. you use migrations for a certain app
  2. in some point at your development, you add proxy models to that app
  3. you need to have specific permissions for that recently created proxy model.
  4. since that app you’re adding the proxy model is not controlled by the syncdb command of django (since it’s on migrations), you can not rely on django’s syncdb command to fix the permissions associated to that model for you.
  5. if you try to run the ‘migrate’ command, nothing happens, no permissions are added, neither any record in django_content_type table.
  6. what’s worst. if you reset the database and start over, then , since migration 0001_initial, the permissions are already there: however , you can not rely on this since you’ve already have a production site going on.
  7. You can not put the data in a data migration either, because, in case the migration is run from 0001 point when the fake models are already defined, it will throw an error when reaching a data migration that tries to reinsert the same data.

Well , what I find as an acceptable solution is the use of send_create_signal in a “fake” migration.

say you have an app which already have 10 migrations run on it. Now you add a proxy model. you create a “fake” schema migration whose only purspose is to send the send_create_signal so the django framework reacts and create the needed content_type and permission records .

In your models.py:

from django.db import models

class TestModel(models.Model):
  ..

class ProxyTestModel(TestModel):
  class Meta:
  proxy=True

and now create an empty schemamigration. this is where you’ll fire the “send_create_signal” event:

class Migration(SchemaMigration):

   def forwards(self, orm):
   # faking proxy model creation
   db.send_create_signal('myapp', ['ProxyTestModel'])

   def backwards(self, orm):
     pass

when you run that migration, it will throw the send_create_signal associated to the model “ProxyTestModel” , in the app “myapp” . the django framework will recognize that and create if they are not created already, the necessary content_type and permissions records on the db.


2 Comments on “Django admin permissions and contenttype table doesn’t update when adding proxy models”

You can track this conversation through its atom feed.

  1. Francis says:

    Works for me, thanks!

  2. Grigoriy Petukhov says:

    Thank you. Your post solved my problem.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>