i wonder here. have emailaddress class has foreignkey relationship user class
class emailaddress(models.model): user = models.foreignkey(allauth_app_settings.user_model, verbose_name=_('user')) email = models.emailfield(unique=app_settings.unique_email, verbose_name=_('e-mail address'))
i have userprofile class has onetoonefield relationship mentioned user so:
class userprofile(models.model): user = models.onetoonefield(user, related_name='profile') attribute= models.charfield("attr", max_length=150, blank=false)
now in admin.py want filter users current user logged in admintool can see emails users share attribute. catch attribute saved in userprofile , need there through email.
basically don't know how access 'attribute' in userprofile. understand want filter users taking email finding user email belongs , compare 'attribute' user send request decide whether show him or not.
def get_queryset(self, request): user = [user whos email in list] qs = [the queryset] [and then] return qs.filter([filter user attribute = request.user attribute])
im using allauth btw. in case wonder
allauth_app_settings.user_model
stands for.
have nice day!
you need use double-underscore syntax follow relationships.
qs.filter(user__userprofile__attribute=request.user.attribute)
Comments
Post a Comment