S
S
Samanta-Smith2019-12-20 17:24:38
Django
Samanta-Smith, 2019-12-20 17:24:38

How to refer to a related model field using django-allauth in a template?

I have an authorization through a social network. The Profile(additional information about the user) model has a OneToOneField() relationship with the User(authorization data) model. How do I render fields from the Profile model when only {% load socialaccount %} account information from django-allauth is passed to the template? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Deleting Account, 2019-12-20
@Samanta-Smith

Use related_name to access the related model.

class Profile(models.model):
      user = models.OneToOneField("User",on_delete = ...., related_name = 'profile')
      ....

In the template
You can also set a value for reletad_name for the default model:
class Profile(models.Model):
     ....
     class Meta:
            default_related_name = 'profile'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question