I need separate files by username and I try this trick:

http://gulopine.gamemusic.org/2007/11/customizing-filenames-without-patching.html

For this model:

class Image(models.Model):
    title       =
models.CharField(u'titulo',max_length=50,blank=False,db_index=True)
    slug        = models.SlugField(u'Id.
usuario',prepopulate_from=['title'],blank=False,unique=True,db_index=True)

    author      = models.ForeignKey(User, verbose_name='autor')
def get_upload_to(self):
        if self.slug<>None:
            return r'images/%s' % (self.author.username,self.slug)
        else:
            return 'images'

def _save_FIELD_file(self, field, filename, raw_contents, save=True):
        original_upload_to = field.upload_to
        field.upload_to = '%s' % self.get_upload_to()
        super(Image, self)._save_FIELD_file(field, filename,
raw_contents, save)
        field.upload_to = original_upload_to

But when this get executed, the object have not the slug or the
author.

This is my view:

@login_required
def add(request):
    if request.method == 'POST':
        form_data = request.POST.copy()
        form_data['author'] = request.user.id
        form_data['slug'] = SlugifyUniquely(form_data['title'],Image)

        form = ImageForm(form_data, request.FILES)
        if form.is_valid():
            img =  form.save()

            return HttpResponseRedirect(reverse('image_detail',
args=[img.slug]))


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to