Currently it seems like it could be pretty disastrous to let users
upload their own files, as you can see from this ticket:
http://code.djangoproject.com/ticket/2983

Of course, one solution is to name your files after the pk of the
record they're associated with, so new uploads will overwrite old
ones.  This is a bit difficult to implement, but it's been done:
http://code.djangoproject.com/wiki/CustomUploadAndFilters

However, this ends up still saving this useless filename in your
database.  Why bother saving something you can intuit?  Ideally, I'd
like to have a model field for this that didn't even touch the
database.

example of what I'd like:
class UserProfile(Model):
  name = CharField(max_length=50)
  mugshot = FakeImageField(upload_to="user%d/
mug",max_width=200,max_height=200,resize="scale")
  background = FakeImageField(upload_to="user%d/
bg",max_width=200,max_height=200,resize="scale")
  some_file = FakeFileField(upload_to="user%d/file",max_size=1000)

Which would generate this sql, totally ignoring those fake fields:
CREATE TABLE "appname_userprofile" ("name" varchar(50) NOT NULL)

But we'd see file inputs when we displayed the ModelForm for this, and
end up with file uploads like "user42/mug.png" -- That is, it could
insert the pk into the pattern, and know exactly where to find out
file.

I've been futzing around trying to implement this.  I can get it to
subclass FileField but generate no sql pretty easily, just by saying
this:
def get_internal_type(self): return ''

However, it chokes when I try to save the modelform, because it tries
to insert values into non-existant database columns.  Somehow I also
need to tell the database cursor to ignore these fields.  Either that,
or I need to find a way to reverse-engineer a model field so that it
will be acceptable in a modelform, without it attempting to insert
anything into the database.

Here's an interesting code snippet that seems to sidestep the issue
entirely http://dpaste.com/49806/

Some final thoughts on the matter:  Oh crap -- the user could still
litter their directory with files that have different extensions --
for example, bg.png, bg.gif, bg.jpg, bg.jpeg, etc.  We may need to
implement a deleting feature after all.
--~--~---------~--~----~------------~-------~--~----~
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