Quantcast

Accessing Associated Models in Django

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Accessing Associated Models in Django

Jason Fawcett
Hi,

  I'm relatively new to PyAMF, and I'm currently trying to get it to
work as an interface between a Flex front-end and a Django back-end.
So far I've been able to get authentication working, and I was able to
map Django User objects to a UserVO object in Flex.  However, I'd also
like to access the User object's groups attribute, but I've been
unsuccessful.  The examples I'd found online suggested mapping the
groups attribute to a string in Flex, but I can't seem to then access
the data in said string; I know that it's there though, because if I
have Flex output the string in an Alert box, it outputs [Object:
Object].  I've also tried mapping the attribute to an Array and to a
custom GroupVO object, but neither would work at all.

  If anyone could give me some suggestions, I would greatly appreciate it.

Cheers,
Jason Fawcett
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing Associated Models in Django

Thijs Triemstra
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Jason,

could you use a site like pastebin.com to post some code that might
clarify things for us and help what you're looking for?

Cheers,

Thijs

On 06/01/2011 05:44 PM, Jason Fawcett wrote:

> Hi,
>
>   I'm relatively new to PyAMF, and I'm currently trying to get it to
> work as an interface between a Flex front-end and a Django back-end.
> So far I've been able to get authentication working, and I was able to
> map Django User objects to a UserVO object in Flex.  However, I'd also
> like to access the User object's groups attribute, but I've been
> unsuccessful.  The examples I'd found online suggested mapping the
> groups attribute to a string in Flex, but I can't seem to then access
> the data in said string; I know that it's there though, because if I
> have Flex output the string in an Alert box, it outputs [Object:
> Object].  I've also tried mapping the attribute to an Array and to a
> custom GroupVO object, but neither would work at all.
>
>   If anyone could give me some suggestions, I would greatly appreciate it.
>
> Cheers,
> Jason Fawcett
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk3meyIACgkQmmLBZjDKywt4+ACeLKunDR9q4JFsQjonP67X4jLm
6+IAnjtyV7e2ortgqdoaTg4n2fPWUdyb
=u2S6
-----END PGP SIGNATURE-----
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing Associated Models in Django

Joni Bekenstein
In reply to this post by Jason Fawcett
Hello,

When you are selecting the User in your django service, are you
including select_related() to actually select related models, like in
your case, Group objects?
https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related

If so, then all you need to do is map Group class just like you mapped
User class, and the in Flex, your UserVO should have an array of
GroupVO objets, I think (haven't used PyAMF for a while).

--
Joni

On Thu, Jun 2, 2011 at 9:00 AM,  <[hidden email]> wrote:

> Send users mailing list submissions to
>        [hidden email]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://lists.pyamf.org/mailman/listinfo/users
> or, via email, send a message with subject or body 'help' to
>        [hidden email]
>
> You can reach the person managing the list at
>        [hidden email]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of users digest..."
>
>
> Today's Topics:
>
>   1. Accessing Associated Models in Django (Jason Fawcett)
>   2. Re: Accessing Associated Models in Django (Thijs Triemstra)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 1 Jun 2011 12:44:54 -0300
> From: Jason Fawcett <[hidden email]>
> To: [hidden email]
> Subject: [pyamf-users] Accessing Associated Models in Django
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
>  I'm relatively new to PyAMF, and I'm currently trying to get it to
> work as an interface between a Flex front-end and a Django back-end.
> So far I've been able to get authentication working, and I was able to
> map Django User objects to a UserVO object in Flex.  However, I'd also
> like to access the User object's groups attribute, but I've been
> unsuccessful.  The examples I'd found online suggested mapping the
> groups attribute to a string in Flex, but I can't seem to then access
> the data in said string; I know that it's there though, because if I
> have Flex output the string in an Alert box, it outputs [Object:
> Object].  I've also tried mapping the attribute to an Array and to a
> custom GroupVO object, but neither would work at all.
>
>  If anyone could give me some suggestions, I would greatly appreciate it.
>
> Cheers,
> Jason Fawcett
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 01 Jun 2011 19:47:14 +0200
> From: Thijs Triemstra <[hidden email]>
> To: PyAMF general discussion <[hidden email]>
> Subject: Re: [pyamf-users] Accessing Associated Models in Django
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Jason,
>
> could you use a site like pastebin.com to post some code that might
> clarify things for us and help what you're looking for?
>
> Cheers,
>
> Thijs
>
> On 06/01/2011 05:44 PM, Jason Fawcett wrote:
>> Hi,
>>
>>   I'm relatively new to PyAMF, and I'm currently trying to get it to
>> work as an interface between a Flex front-end and a Django back-end.
>> So far I've been able to get authentication working, and I was able to
>> map Django User objects to a UserVO object in Flex.  However, I'd also
>> like to access the User object's groups attribute, but I've been
>> unsuccessful.  The examples I'd found online suggested mapping the
>> groups attribute to a string in Flex, but I can't seem to then access
>> the data in said string; I know that it's there though, because if I
>> have Flex output the string in an Alert box, it outputs [Object:
>> Object].  I've also tried mapping the attribute to an Array and to a
>> custom GroupVO object, but neither would work at all.
>>
>>   If anyone could give me some suggestions, I would greatly appreciate it.
>>
>> Cheers,
>> Jason Fawcett
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
>
> iEYEARECAAYFAk3meyIACgkQmmLBZjDKywt4+ACeLKunDR9q4JFsQjonP67X4jLm
> 6+IAnjtyV7e2ortgqdoaTg4n2fPWUdyb
> =u2S6
> -----END PGP SIGNATURE-----
>
>
> ------------------------------
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> End of users Digest, Vol 41, Issue 1
> ************************************
>
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing Associated Models in Django

Joni Bekenstein
In reply to this post by Jason Fawcett
According to the django docs
https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related,
selected_related would be more like:
user_obj = User.objects.select_related().get(username=username)
With the ().

On the other hand, in your UserVO, I think groups should be an Array,
not a String.

--
Joni

On Thu, Jun 2, 2011 at 10:59 PM, Jason Fawcett <[hidden email]> wrote:

> Sure thing.  My gateway.py file is here:
> http://pastebin.com/gN5S4x1X
> My Flex application file, Revolution.mxml is here:
> http://pastebin.com/wianAGyf
> and my UserVO file is here:
> http://pastebin.com/Axb0tQiL
>
> When run as-is, and when provided with a valid username/password, an
> Alert box will pop up showing 'Groups: [Object: Object]', which says
> to me that the data is there, it's simply not accessible in this
> manner.  What I'd like to be able to do is access the individual
> attributes of each group as though it were an object (i.e.
> currentUser.groups[0].name).
>
> Again, any assistance would be greatly appreciated.
>
> Cheers,
> Jason Fawcett
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing Associated Models in Django

Jason Fawcett
In reply to this post by Jason Fawcett
So, turns out the Gateway.py file I posted was a bit outdated (I'm
syncing between my desktop and laptop), and it should actually be
select_related().

Regardless, mapping it to an Array seems to have worked.  I could have
sworn that I'd tried that before, but I guess I was mistaken.

Thanks for the help!

Cheers,
Jason Fawcett

> Message: 1
> Date: Thu, 2 Jun 2011 09:24:15 -0300
> From: Joni Bekenstein <[hidden email]>
> To: [hidden email]
> Subject: Re: [pyamf-users] Accessing Associated Models in Django
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hello,
>
> When you are selecting the User in your django service, are you
> including select_related() to actually select related models, like in
> your case, Group objects?
> https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related
>
> If so, then all you need to do is map Group class just like you mapped
> User class, and the in Flex, your UserVO should have an array of
> GroupVO objets, I think (haven't used PyAMF for a while).
>
> --
> Joni
>
> On Thu, Jun 2, 2011 at 9:00 AM,  <[hidden email]> wrote:
>> Send users mailing list submissions to
>> ? ? ? ?[hidden email]
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> ? ? ? ?http://lists.pyamf.org/mailman/listinfo/users
>> or, via email, send a message with subject or body 'help' to
>> ? ? ? ?[hidden email]
>>
>> You can reach the person managing the list at
>> ? ? ? ?[hidden email]
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of users digest..."
>>
>>
>> Today's Topics:
>>
>> ? 1. Accessing Associated Models in Django (Jason Fawcett)
>> ? 2. Re: Accessing Associated Models in Django (Thijs Triemstra)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Wed, 1 Jun 2011 12:44:54 -0300
>> From: Jason Fawcett <[hidden email]>
>> To: [hidden email]
>> Subject: [pyamf-users] Accessing Associated Models in Django
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> Hi,
>>
>> ?I'm relatively new to PyAMF, and I'm currently trying to get it to
>> work as an interface between a Flex front-end and a Django back-end.
>> So far I've been able to get authentication working, and I was able to
>> map Django User objects to a UserVO object in Flex. ?However, I'd also
>> like to access the User object's groups attribute, but I've been
>> unsuccessful. ?The examples I'd found online suggested mapping the
>> groups attribute to a string in Flex, but I can't seem to then access
>> the data in said string; I know that it's there though, because if I
>> have Flex output the string in an Alert box, it outputs [Object:
>> Object]. ?I've also tried mapping the attribute to an Array and to a
>> custom GroupVO object, but neither would work at all.
>>
>> ?If anyone could give me some suggestions, I would greatly appreciate it.
>>
>> Cheers,
>> Jason Fawcett
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Wed, 01 Jun 2011 19:47:14 +0200
>> From: Thijs Triemstra <[hidden email]>
>> To: PyAMF general discussion <[hidden email]>
>> Subject: Re: [pyamf-users] Accessing Associated Models in Django
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi Jason,
>>
>> could you use a site like pastebin.com to post some code that might
>> clarify things for us and help what you're looking for?
>>
>> Cheers,
>>
>> Thijs
>>
>> On 06/01/2011 05:44 PM, Jason Fawcett wrote:
>>> Hi,
>>>
>>> ? I'm relatively new to PyAMF, and I'm currently trying to get it to
>>> work as an interface between a Flex front-end and a Django back-end.
>>> So far I've been able to get authentication working, and I was able to
>>> map Django User objects to a UserVO object in Flex. ?However, I'd also
>>> like to access the User object's groups attribute, but I've been
>>> unsuccessful. ?The examples I'd found online suggested mapping the
>>> groups attribute to a string in Flex, but I can't seem to then access
>>> the data in said string; I know that it's there though, because if I
>>> have Flex output the string in an Alert box, it outputs [Object:
>>> Object]. ?I've also tried mapping the attribute to an Array and to a
>>> custom GroupVO object, but neither would work at all.
>>>
>>> ? If anyone could give me some suggestions, I would greatly appreciate it.
>>>
>>> Cheers,
>>> Jason Fawcett
>>> _______________________________________________
>>> PyAMF users mailing list - [hidden email]
>>> http://lists.pyamf.org/mailman/listinfo/users
>>>
>>
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.11 (GNU/Linux)
>>
>> iEYEARECAAYFAk3meyIACgkQmmLBZjDKywt4+ACeLKunDR9q4JFsQjonP67X4jLm
>> 6+IAnjtyV7e2ortgqdoaTg4n2fPWUdyb
>> =u2S6
>> -----END PGP SIGNATURE-----
>>
>>
>> ------------------------------
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>>
>>
>> End of users Digest, Vol 41, Issue 1
>> ************************************
>>
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 2 Jun 2011 22:59:10 -0300
> From: Jason Fawcett <[hidden email]>
> To: [hidden email]
> Subject: Re: [pyamf-users] users Digest, Vol 41, Issue 1
> Message-ID: <BANLkTi=[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Sure thing.  My gateway.py file is here:
> http://pastebin.com/gN5S4x1X
> My Flex application file, Revolution.mxml is here:
> http://pastebin.com/wianAGyf
> and my UserVO file is here:
> http://pastebin.com/Axb0tQiL
>
> When run as-is, and when provided with a valid username/password, an
> Alert box will pop up showing 'Groups: [Object: Object]', which says
> to me that the data is there, it's simply not accessible in this
> manner.  What I'd like to be able to do is access the individual
> attributes of each group as though it were an object (i.e.
> currentUser.groups[0].name).
>
> Again, any assistance would be greatly appreciated.
>
> Cheers,
> Jason Fawcett
>
> On Thu, Jun 2, 2011 at 9:00 AM,  <[hidden email]> wrote:
>> Message: 2
>> Date: Wed, 01 Jun 2011 19:47:14 +0200
>> From: Thijs Triemstra <[hidden email]>
>> To: PyAMF general discussion <[hidden email]>
>> Subject: Re: [pyamf-users] Accessing Associated Models in Django
>> Message-ID: <[hidden email]>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi Jason,
>>
>> could you use a site like pastebin.com to post some code that might
>> clarify things for us and help what you're looking for?
>>
>> Cheers,
>>
>> Thijs
>>
>> On 06/01/2011 05:44 PM, Jason Fawcett wrote:
>>> Hi,
>>>
>>> ? I'm relatively new to PyAMF, and I'm currently trying to get it to
>>> work as an interface between a Flex front-end and a Django back-end.
>>> So far I've been able to get authentication working, and I was able to
>>> map Django User objects to a UserVO object in Flex. ?However, I'd also
>>> like to access the User object's groups attribute, but I've been
>>> unsuccessful. ?The examples I'd found online suggested mapping the
>>> groups attribute to a string in Flex, but I can't seem to then access
>>> the data in said string; I know that it's there though, because if I
>>> have Flex output the string in an Alert box, it outputs [Object:
>>> Object]. ?I've also tried mapping the attribute to an Array and to a
>>> custom GroupVO object, but neither would work at all.
>>>
>>> ? If anyone could give me some suggestions, I would greatly appreciate it.
>>>
>>> Cheers,
>>> Jason Fawcett
>>> _______________________________________________
>>> PyAMF users mailing list - [hidden email]
>>> http://lists.pyamf.org/mailman/listinfo/users
>>>
>>
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.11 (GNU/Linux)
>>
>> iEYEARECAAYFAk3meyIACgkQmmLBZjDKywt4+ACeLKunDR9q4JFsQjonP67X4jLm
>> 6+IAnjtyV7e2ortgqdoaTg4n2fPWUdyb
>> =u2S6
>> -----END PGP SIGNATURE-----
>>
>>
>> ------------------------------
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>>
>>
>> End of users Digest, Vol 41, Issue 1
>> ************************************
>>
>
>
> ------------------------------
>
> Message: 3
> Date: Fri, 3 Jun 2011 08:02:15 -0300
> From: Joni Bekenstein <[hidden email]>
> To: PyAMF general discussion <[hidden email]>
> Subject: Re: [pyamf-users] Accessing Associated Models in Django
> Message-ID: <BANLkTi=[hidden email]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> According to the django docs
> https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related,
> selected_related would be more like:
> user_obj = User.objects.select_related().get(username=username)
> With the ().
>
> On the other hand, in your UserVO, I think groups should be an Array,
> not a String.
>
> --
> Joni
>
> On Thu, Jun 2, 2011 at 10:59 PM, Jason Fawcett <[hidden email]> wrote:
>> Sure thing. ?My gateway.py file is here:
>> http://pastebin.com/gN5S4x1X
>> My Flex application file, Revolution.mxml is here:
>> http://pastebin.com/wianAGyf
>> and my UserVO file is here:
>> http://pastebin.com/Axb0tQiL
>>
>> When run as-is, and when provided with a valid username/password, an
>> Alert box will pop up showing 'Groups: [Object: Object]', which says
>> to me that the data is there, it's simply not accessible in this
>> manner. ?What I'd like to be able to do is access the individual
>> attributes of each group as though it were an object (i.e.
>> currentUser.groups[0].name).
>>
>> Again, any assistance would be greatly appreciated.
>>
>> Cheers,
>> Jason Fawcett
>
>
> ------------------------------
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
>
>
> End of users Digest, Vol 41, Issue 2
> ************************************
>
_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Loading...