You could replace in the view:

if form_upload.is_valid():
  form_upload.save()


# with this:

if form_upload.is_valid():
  form_upload.user = request.user
  form_upload.save()


You may also want to not display the user field in the form. You can do it
by defining an 'exclude' Meta class attribute for the ModelForm, as done
below. I believe you can also hide a field in the form by marking it
"editable=False" in its model's field definition.

class FormUpload(forms.ModelForm):

    class Meta:
        model = ModelName
        exclude = ('user',)




On Tue, Jul 14, 2009 at 5:53 PM, djangonoob <ye.eug...@gmail.com> wrote:

>
> I'm using django 1.02, Ubuntu 9.04, python 2.6.2
>
> Issue: I am creating a simple application that allows users to upload
> images.
> I'm using the User from django.contrib.auth.models to manage my users.
> For the image class, i have a ForeignKey to the user and a ImageField
> to store my images
>
> My application works perfectly, except that:
> when the user uploads images, the images will be linked to the user
> himself.
> However, on the upload form, i have a option selection box where all
> the usernames are selectable.
>
> How do i fix the views.py, models.py such that the user can only
> upload images using
> his own username and at the same time, without having to select his
> username from the dropdown selection box?
>
> The following is my code:
> http://dpaste.com/66944/
>
> Thank you in advance.
> >
>


-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to