Since you're using a foreign key, the relationship is one-to-many. I.e.,
one Profile to many Complaints. This means there is no "set" of profiles
for a complaint. There /is/, however, a single Profile object related to
each Complaint. In your case, it's "user". E.g: complaint.user

_Nik

On 5/8/2013 3:03 AM, sachin wrote:
> Hello all,
>
> Accessing the foreign key object is simple using _set
> lets say I have a models like:
>
> class Profile(models.Model):
>     """
>     extended auth user profile
>     """
>     user = models.OneToOneField(User)
>     emp_id = models.CharField(max_length=10)
>     phone_number = models.CharField(max_length=15)
>
>     def __unicode__(self):
>         return "%s" % self.user
>
> class Complaint(models.Model):
>     """
>     users complaints
>     """
>     user = models.ForeignKey(Profile)
>     complaint = models.TextField()
>    
>
> I can access Profile's objects as
>
> user_profile = Profile.objects.get(user=USER_INSTANT)
>
> and then
>
> user_profile.complaint_set.values()
>
> but can I access it reversely ??
>
> I mean
>
> complaint.profile_set.values() like this
>
> -- 
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to