问题
I have just moved a site from Django-CMS 2.3.5 to 2.4.1 (with help from Stackoverflow) under Django 1.4.
I am now upgrading to Django 1.5, which is only hard because I need to update the old separate user profile to a new custom user model. I followed the excellent instructions here, and also replaced all references to User
with settings.AUTH_USER_MODEL
.
Unfortunately Django-CMS's models apparently still refer to User
though: when I type manage.py runserver
, I get this error:
CommandError: One or more models did not validate:
cms.pagemoderatorstate: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.globalpagepermission: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.pagepermission: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.pageuser: 'user_ptr' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.pageuser: 'created_by' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
cms.pageusergroup: 'created_by' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
How can I get Django-CMS to use the new user model?
thanks!
回答1:
There is very simple solution. Just need to register your custom user before importing CMSPlugin. Example:
from django.db import models from django.contrib.auth import models as auth_models from django.contrib.auth.models import AbstractUser class User(AbstractUser): telephone = models.CharField(max_length=100) email = models.CharField(max_length=100) auth_models.User = User from cms.models import CMSPlugin
回答2:
For others with this question, here is my summary of what I have learned from https://github.com/divio/django-cms/issues/1798.
There are four potential options:
- If you need your custom user model to have a name other than User, you'll need to wait.
- You can call the custom user model User - though when I tried this, I got errors about clashes with related m2m fields. There are some further details on the above link which may help resolve this.
- Django 1.5 still lets you use user profiles. So if you are ok with using a deprecated feature, you can still use Django-CMS 2.4 and Django 1.5 with user profiles instead of a custom user model. (I misread the Django docs here and thought user profiles were not supported in Django 1.5.)
- You can often get away without either a user profile or a custom user model - they are best used to add data specifically for user authentication. Instead, you can use another model with a one-to-one relationship to User, and use the reverse relationship to access it.
In my case, I am going to go with #3 in the short-run and #4 in the long-run.
来源:https://stackoverflow.com/questions/16601412/upgrading-django-to-1-5-with-django-cms-user-model-issue