Django User model, adding function

后端 未结 3 1731
醉话见心
醉话见心 2021-02-01 03:56

I want to add a new function to the default User model of Django for retrieveing a related list of Model type.

Such Foo model:

class Foo(models.Model):
          


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 04:26

    You can add a method to the User

    from django.contrib import auth
    auth.models.User.add_to_class('get_related_foo_models', get_related_foo_models)
    

    Make sure, you have this code within the models.py or some other file which gets imported in the startup of django.

提交回复
热议问题