开发者

GAE Django nonrel extend user model

I'm trying to extend User models with my custom model by inheriting from it like this:

class Profile(User):
   ...

I would like to add my custom fields to the User model but django nonrel fails with an error:

DatabaseEr开发者_JAVA技巧ror: Multi-table inheritance is not supported by non-relational DBs.

So how I can solve this problem? I definitely need my custom fields in User model.


Instead of overriding the User model you should create another class that holds the additional fields and bind it to User model by a 1-to-1 relationship.

from django.contrib.auth.models import User

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    nickname = models.CharField(max_length=50)
    ...
    ...


You Cannot do something like that in google-app-engine. If you want to have relationship in your model. You should denormailse your model in such a way that the same can be achieved in appengine's way.To know more about modeling in appengine . You can have go through the following links.

modeling in appengine

Daily profeth modeling in appengine


I wanted the request.user object to be the normal User object, but with added fields. The accepted answer doesn't allow that, as UserProfile has a member "user" instead of being a user.

This article explains how to instead inherit from User.

The steps in brief:

  • Make CustomUser inherit from User
  • Set up a custom authentication backend to return CustomUser

Have not tried it yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜