Hello,

I think the source of your frustration is that you started on the wrong
track. If you create a global variable here, *all* your users will see the
same fields. I guess it’s not really the thing you want.

You have several other options here:

1) Add a user setting in the database

If you create a separate model with your User model as its primary key
(thus, creating a OneToOne relation between a User and Setting), you can
store these values in the database, this way persisting it between user
sessions

2) Session variables

You can use Django’s session framework. Here[1] is some help on this.

3) Cache

This can be similar to 1) or 2), or somewhat the combination of the two.
This way you store such values in a cache, like MemCached. This solves some
possible garbage collection problems and database storage issues. More on
accessing the cache here[2].

Hope this helps.

Best,
Gergely

[1]
https://docs.djangoproject.com/en/1.7/topics/http/sessions/#using-sessions-in-views
[2]
https://docs.djangoproject.com/en/1.8/topics/cache/#the-low-level-cache-api

2015-05-13 23:13 GMT+02:00 Henry Versemann <[email protected]>:

> I have a list of one or more items being returned back to my application
> as a response from a call to an API. In this particular part of the process
> depending on the data keys selected by the user, if any some data fields
> will be formatted automatically. When that happens I need to add the keys
> to those new automatically-generated fields to the list of data keys
> originally entered by the user. In the case where there's only one item
> being returned, this isn't a problem, but when I get back multiple objects
> in my response I only want to add the new data field keys to the display
> key list once. The flag will be initialized to false at the beginning of
> the process which processes all of the responses. So the only way I could
> think of to do this would be to setup some kind of global variable that can
> be checked and when set to "false" then and only then update the display
> key list with the keys to the new data fields. Then also at the same time
> set the flag to "true", so the update doesn't happen again for each and
> every subsequent item in the list of response objects. At least not until
> the next request is sent and its response is being processed.
>
> So what are my options for creating a global Boolean variable(or any other
> global variable type for that matter), for accomplishing the above task?
>
> So far I've tried using a "global" keyword when setting up a variable, as
> well as declaring a variable in a globalvars.py file, importing the
> file and trying to reference it something like this:
>
> globalvars.display_key_list_updated = True or False
>
> But I keep getting errors of one sort or another with each way I've tried
> so far (mostly exceptions.NameError).
>
> This is my first attempt at trying to setup and use some kind of a global
> variable, so its kind of frustrating, and I'm probably making it harder
> than it is, but my lack of experience is getting in the way.
>
> Thanks for the help. It is much appreciated.
>
> Henry
>
>  --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/8a1f173b-de34-4e34-8c34-e1512b46a05d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8a1f173b-de34-4e34-8c34-e1512b46a05d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CACczBU%2BxAcmgAuxw9spYAZ2L2-EaQ%2BDBNSM9eLFxnMoDT9sq8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to