-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using AutoOneToOneField with proxy model #88
Comments
Just verified that Here is my project which use a proxy model of Auth.User to filter out staff and superuser, also to display by email instead of username. Since I use/mix with Firebase SDK, username is Firebase's UID and hidden from end user. My admin stuff can only recognize end users by their email addresses. from django.contrib.auth.models import UserManager, User
class EndUserManager(UserManager):
def get_queryset(self):
return super().get_queryset().filter(is_staff=False, is_superuser=False)
class EndUser(User):
objects = EndUserManager()
class Meta:
proxy = True
def __str__(self):
return "%s" % (self.email or self.username) Now I've two models which both are One-To-One relation with class Profile(models.Model):
owner = AutoOneToOneField(EndUser, on_delete=models.CASCADE, related_name='profile')
def __str__(self):
return "%s" % self.owner
class Tutor(models.Model):
owner = OneToOneField(EndUser, on_delete=models.CASCADE, related_name='tutor')
def __str__(self):
return "%s" % self.owner When I obtain an instance of >>> user = User.objects.get(pk=100)
>>> user.profile
AttributeError: 'User' object has no attribute 'profile'
>>> user.tutor
<Tutor: 100@brewingapps.com> I know I can obtain instance of Using a patched version class FixedAutoOneToOneField(AutoOneToOneField):
def contribute_to_related_class(self, cls, related):
setattr(
cls._meta.concrete_model,
related.get_accessor_name(),
AutoSingleRelatedObjectDescriptor(related)
) |
Thanks for this research! Unfortunately, I've never used the |
When using AutoOneToOneField with Proxy model, I've a hard time to get the related model. The similar setup with OneToOneField doesn't have problem. While I check the code I found a difference here:
Studying Django's code:
When calling
setattr(...)
, should AutoOneToOneField also pass incls._meta.concrete_model
instead?The text was updated successfully, but these errors were encountered: