4👍
You just need to assign the model attribute of your queryset
users = User.objects.all()
users.model = MyProxyUser
users.first().say_hello()
Edit: For assigning proxy class to a django model object, try
user = User.objects.all()
user.__class__ = MyProxyUser
0👍
Adding to Ramast’s answer, you can also build a function on your proxy model class to consistently do this for you:
class MyProxyUser(User):
...
@staticmethod
def from_user(user: UserManager):
""" Get a PAUser classed instance from a User object.
Useful for Signals and other Django defaults that send base User objects.
"""
user.model = PAUser
return user
...
- [Django]-(Python/Django): How do I keep my production db in sync (scheme and data) and with dev pc db?
- [Django]-Count how many fields a model has
- [Django]-How to create combobox with django model?
- [Django]-Create HTML Mail with inline Image and PDF Attachment
- [Django]-Postgres connection details in django and chef
Source:stackexchange.com