Thanks very much Laurent, I will have a go with that this morning. 
Regards, N/ 

On Monday, 19 August 2013 16:25:00 UTC+1, Laurent Meunier wrote:
>
> On 19/08/2013 17:05, Nigel Legg wrote: 
> > In the app I am building for data analysis, I want all logged in users 
> > to be able to access all parts of the system, but only to have access to 
> > the datafiles they hae uploaded themselves.  Can I use 
> > django.contrib.auth to filter the full list of datafiles according to 
> > the user object? 
> > If so, how do I go about this? I'm thinking of attaching a user_id field 
> > to the file when it is uploaded, and then filtering against that wen a 
> > logged in user goes to the list of files, but I'm not sure how I would 
> > implement this. 
> > Any help greatly appreciated. 
>
> Hi, 
>
> Your best option is to add a foreign key to your user model (usually 
> django.contrib.auth.models.User) in your model that handles your 
> datafiles. 
>
> from django.contrib.auth.models import User 
>
> class Datafile(models.Model): 
>      user = models.ForeignKey(User) 
>      ... 
>
>
> When a user upload a datafile, don't forget to set the user field: 
>
> mydatafile.user = request.user 
>
>
> And then you can filter datafiles: 
>
> Datafile.objects.filter(user=request.user) 
>
>
> -- 
> Laurent Meunier <[email protected] <javascript:>> 
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to