cheers :D
2010/9/8 akaariai <akaar...@gmail.com> > On 8 syys, 19:26, Bachir <bachir...@gmail.com> wrote: > > This is an example: > > > > class UploadItem(models.Model): > > file = models.FileField(upload_to=UploadItem.get_directory) > > > > class Meta: > > abstract = True > > > > # I want videos to be storred in 'videos/' directory > > class Video(UploadItem): > > def get_directory(self, instance, filename): > > return 'videos/' > > But this doesn't work, i am getting this error: > > > > file = models.FileField(upload_to=UploadItem.get_directory) > > NameError: name 'UploadItem' is not defined > > I haven't tried this, or used upload_to with filefields, but according > to documentation something like this should work: > > def upload_item_upload_to(instance, filename): > if isinstance(instance, Video): > return 'videos/' > if isinstance(instance, SomeOtherModel) > return 'something_else/' > return 'default_path/' > > class UploadItem(models.Model): > file = models.FileField(upload_to=upload_item_upload_to) > > Or maybe a cleaner way: > > def upload_item_upload_to(instance, filename): > return instance.upload_path > > class UploadItem(models.Model): > file = models.FileField(upload_to=upload_item_upload_to) > upload_path = 'default_path/' > > class Video(UploadItem): > upload_path = 'videos/' > > Hope this helps, import pdb; pdb.set_trace() as first line in > upload_item_upload_to function is a good way to see > how to proceed... > > - Anssi > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.