Russ, Perhaps you are correct. I am using 5335 patched with #3297, but guess I just don't know how to code (or name?) the necessary method.
This explanation of what I'm doing may help: class ToolRun(models.Model): revision = models.IntegerField(blank=True, null=True) project = models.ForeignKey(Project, blank=False) tool = models.ForeignKey(Tool) input_file = models.FileField(upload_to="/") The form is created like this: FormClass = forms.models.form_for_model(ToolRun) post_data = request.POST.copy() post_data.update(request.FILES) form = FormClass(post_data) The form has the 'project' and 'revision' fields hidden and initialized. The form asks the user to enter the 'tool' and 'input_file'. Once POSTed, if the input data is valid I check in the view for an existing ToolRun instance with matching project, tool and input_file. If what was entered does not exist, create a new ToolRun and upload the file. If what was entered does exist, simply upload the (identically named) file. clean = form.cleaned_data try: toolrun = ToolRun.objects.get(project=clean['project'], tool=clean['tool'], input_file=clean['input_file'] ['filename']) save_instance(form, toolrun) except ObjectDoesNotExist: toolrun = form.save() Problems I have are threefold: 1. With either type of save I cannot seem to override the 'upload_to' location string before the file contents are saved. 2. If a file with the same name already exists in the appropriate 'upload_to' location, I want to delete that file prior to saving the new file. 3. I really don't want the 'upload_to' path prepended to the filename stored in 'input_file' in the ToolRun instance. I imagine that newforms has hooks to let me solve this, I just cannot seem to find them. FWIW, I do have the following additional methods in the ToolRun class: def save(self): # set the upload directory for the input file for f in self._meta.fields: if f.attname == 'input_file': f.upload_to = "/%d/%d' % (self.project.id, self.tool.id) super(ToolRun, self).save() This has no effect on where the uploaded files are stored, so I added this "save_FOO_file" method to the ToolRun model class: def save_input_file_file(filename, raw_contents): # save it in the correct subdir .... According to the debugger, this function is never called. Thanks for your assistance! Graham On Jun 6, 6:41 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On 6/7/07, grahamu <[EMAIL PROTECTED]> wrote: > > > > > Does anyone here know where/how I should override the default save > > method for a newforms-based FileField? > > It looks like you're looking for the functionality requested in ticket > #3297. The patch that is there works, but probably won't be accepted > as-is; I've been working on a slightly different patch, which I should > be able to put up for comment tonight. > > However, as a stop-gap measure, the existing patch on #3297 will > suffice. The differences between my patch and the existing #3297 are > subtle; transitioning from using one patch to the other shouldn't be > too onerous. > > Yours, > Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---