0

I've extended the standard User with a Profile model using a one-to-one relationship:

class Profile(models.Model):
    user = models.OneToOneField(User, primary_key=True, editable=False)
    # Additional user information fields

This is in an app called account_custom. The issue is that in the admin site, I would like this model to show up along with User under "Authentication and Authorization".

I was able to make this show up in the right place in the admin by setting Meta.app_label:

class Profile(models.Model):
    class Meta:
        app_label = 'auth'
        db_table = 'account_custom_profile'

I set Meta.db_table so this uses the existing database table, and everything seems to function properly.

The problem is that Django wants to generate migrations for this, one in account_custom to delete the table and one in auth to create it again. I'm guessing this would either fail or wipe out the data depending on the order the migrations are run, but the deeper problem is that it's trying to create a migration in auth which isn't part of my code base.

Is there a way around this, or is there some better way to control where a ModelAdmin shows up in the admin site?

Adam
  • 938
  • 1
  • 8
  • 22
  • 1
    If all you want is to have user profile in admin along with user the better option is too show user profile inline in user admin, checkout this answer http://stackoverflow.com/questions/4565814/django-user-userprofile-and-admin .. Simple is better than complex ;) – Aamir Rind Mar 24 '17 at 00:18
  • That is much cleaner and simpler, thanks! – Adam Mar 24 '17 at 22:50

0 Answers0