Accessing to my user

15 views
Skip to first unread message

somen...@gmail.com

unread,
Apr 2, 2015, 11:24:48 AM4/2/15
to django...@googlegroups.com
I have this
class Persona(models.Model):
7        """Person class:
8             * user: a user
9             * presentation: some paragraph for other knowing you
10             * availability: the availability of user for knowing new people. See 'AVAILABILITY' tuples explanation
11        """
12        # 'Available' means you want to meet new people now
13        # and 'Unavailable' means you don't want to meet new people.
14        # Useful for not anoying you new users.
15        AVAILABILITY = (
16                ('Y', 'Available'),
17                ('N', 'Unavailable'),
18        )
19
20
21        user = models.OneToOneField(User)
22        presentation = models.CharField(max_length=254, blank=True)
23        availability = models.CharField(max_length=1, choices=AVAILABILITY, default='Y')
24
25        def __str__(self):
26                return self.user.username
27
28        def username(self):
29                return self.user.username
30
31        def full_name(self):
32                return "{0}, {1}".format(self.user.last_name, self.user.first_name)
33


How can I do to acces to Persona which has user.username=='foo'?

Thanks in advance,

Filipe Ximenes

unread,
Apr 2, 2015, 11:29:46 AM4/2/15
to django...@googlegroups.com
Try:
p = Persona.objects.get(user__username='foo')

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/599f61a6-6f87-4dd7-a3f2-7a4b3693a185%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
  
Filipe Ximenes
+55 (81) 8245-9204
Vinta Software Studio
http://www.vinta.com.br

Simon Charette

unread,
Apr 2, 2015, 11:31:22 AM4/2/15
to django...@googlegroups.com
Hi!

Personna.objects.get(user__username='foo') should do.

Simon

somen...@gmail.com

unread,
Apr 2, 2015, 12:40:44 PM4/2/15
to django...@googlegroups.com
Perfect.

El dijous, 2 abril de 2015 17:29:46 UTC+2, Filipe Ximenes va escriure:
Reply all
Reply to author
Forward
0 new messages