Hi Hebert, ok thanks i got what u mean. But what happens if my model is now like this:
# models.py class Images(models.Model): title = models.CharField(max_length=200) images = models.ImageField(upload_to='userimages') user = models.ForeignKey(User) public = models.BooleanField() def __str__(self): return self.title # check to see for the upload form: does it take in user : as in who is uploading it? class Images_Upload_Form(ModelForm): class Meta: model = Images exclude = ['user'] # views.py @login_required def image_upload(request): if request.user.is_authenticated(): #form = inlineformset_factory(User,Images,can_delete=False, max_num=1,extra=1,) form = Images_Upload_Form(request.POST, request.FILES) username = request.user #form = Images_Form(request.POST, request.FILES) if request.method == 'POST': form_upload = form if form_upload.is_valid(): img_instance=form_upload.save(commit=False) img_instance.user=username img_instance.save() #form_upload.save() return HttpResponseRedirect('/tag_images/') # here may be now add tags else: #form_upload = Images_Form() form_upload = Images_Upload_Form() #form_upload = Images_Upload_Form(initial={'user': request.user}) #form_upload = form(instance=username) variables = RequestContext(request , {'form_upload':form_upload,'username':username,}) return render_to_response('upload_image.html',variables ) else: return HttpResponseRedirect('/login/') # urls.py urlpatterns = patterns('', (r'^upload_form/$','school.views.image_upload'), ) Given teh above code, i want to use a generic view to allow a user ( who have already signed up ) to upload images? ( assuming i want to use 'django.views.generic.create_update.create_object' for the Image model ) So in this case, how do i use a generic view, for the Image model, to allow users to upload images, but save the current user in the user attribute of the Image model using form_class ? ( ( as per what i did in image_upload function in views.py ) thanks a lot! On Jul 26, 4:49 pm, Frédéric Hébert <fg.heb...@gmail.com> wrote: > Hi, > > AFAICS, it's nearly impossible to do this in the way you want to. > > set_pub_date is an another view which does a CRUD operation like > generic view create_object and you pass it to extra_context which is > relevant to a template operation. > > extra_context declares new objects in the template and is not intended > to add new control logic on the form. > > Maybe you wanted to pass to extra_context a new PressReleaseCRUD form > and uses it in place of generic views' form ? In that case why do you > use a generic view ? > > I wonder why you don't want to do this logic on your model instance ? > > Frédéric > > --http://www.openidfrance.fr/fhebert --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---