Django inbuilt Model

11 views
Skip to first unread message

Soumen Khatua

unread,
Jul 28, 2019, 12:49:35 PM7/28/19
to django...@googlegroups.com
Hi Folks,
I Extended Profile Model from dajngo inbuilt User model but Now I want call all the details those are associated with Username in Profile model. I got the username but how i cann call it in Profile model.

Ex:
class Profile(models.Model):
user = models.ForeignKey(User,related_name = 'user_model,..........)

data = Profile.objects.filter(user = username)

But it's not working please help me guys.

Thank You

Regards,
Soumen

Juhana Jauhiainen

unread,
Jul 28, 2019, 1:58:21 PM7/28/19
to django...@googlegroups.com
Hi Soumen,

You could try with 
profiles = Profile.objects.filter(user__username=username)

I would also suggest changing your model definition to something like
class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
Then you will have exactly one Profile per User and you can also access the Profile from user object with 
user.profile
FYI, related_name defines the name of reverse relation. So in your case it would mean you can access the profile from a user object with
user.user_model
Which is probably not what you want..

-Juhana

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WY%2BUNTU6UOAKyOxMWg24dAsmc7eB7%3D9kZTDjiukn3%2BKJQ%40mail.gmail.com.

Soumen Khatua

unread,
Jul 29, 2019, 3:13:03 AM7/29/19
to django...@googlegroups.com
Thank you for your response.

Regards, 
Soumen

Reply all
Reply to author
Forward
0 new messages