开发者

How to extend request.user with own functions in django?

I've seen some nifty code on django-ratings documentation and like to create something similar. After googling around for now 2 weeks I got no idea on how to do this.

Maybe you could help me what to search for or where to get some docs?

Code from django-ratings docs:

...
response = AddRatingView()(request, **params)
    if response.status_code == 200:
        if response.content == 'Vote recorded.':
            request.user.add_xp(settings.XP_B开发者_如何转开发ONUSES['submit-rating'])
        return {'message': response.content, 'score': params['score']}
    return {'error': 9, 'message': response.content}
...

My Problem:

request.user.add_xp(settings.XP_BONUSES['submit-rating'])

So i'd like to do something like this:

request.user.my_shiny_function(foobar)

Thanks in advance, Thomas


Check out proxy models: http://docs.djangoproject.com/en/dev/topics/db/models/#id8


I think the code sample you're sighting seems to have been picked from somewhere else (it's not part of the django-ratings code - a simple grep -ir "add_xp" on the source directory shows that text is only in Readme.rst).

If you could explain why you need the functionality you're looking for here, maybe we could help some more. In the mean time, you can look at rolling your own custom backend, extending the default User model and then adding other "nifty" features to it :).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜