Reputation: 1348
I'm working on this project and i'm extending Django's base user model in order to have emails as usernames. I've got the following project structure with two apps (client and showroom)
. project
.. client
... models
.... Client
.. showroom
... models
.... Image
Client inheritates AbstractBaseUser like this:
class Client(AbstractBaseUser):
email = models.CharField(max_length=255, unique=True)
firstname = models.CharField(max_length=50)
etc...
Image has a Foreign Key to my Client model:
class Image(models.Model):
client = models.ForeignKey(_('Client'), settings.AUTH_USER_MODEL, blank=True, null=True, limit_choices_to=Q(groups__name = 'website_user'))
etc...
And in my settings.py (which is not called settings.py, don't think it's relevant but just in case) I have got this:
INSTALLED_APPS = (
'django.contrib.auth',
etc...
'client',
'showroom',
etc...
)
AUTH_USER_MODEL = 'client.Client'
Now, when I try to run the project, syncdb, migrate or whatever else that has to do with the database, I get this error:
showroom.Image.client: (fields.E300) Field defines a relation with model 'Client', which is either not installed, or is abstract.
Of course, when I remove the foreign key to Client in my Image model, everything works fine.
I have googled this a lot and most solutions suggest that my apps are not properly installed, but they seem to be as shown in my config file. So I guess this has something to do with inheriting django's AbstractBaseUser, but i can't see why this wont work for me, as my code is very similar to the one in the official docs.
Anyway, thanks in advance for your help.
Upvotes: 1
Views: 2833
Reputation: 3802
First argument of ForeignKey
should be a model or a name of a model. You pass _('Client')
what I think is verbose_name
.
Try this:
client = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('Client'), blank=True, null=True, limit_choices_to=Q(groups__name = 'website_user'))
Upvotes: 3