On Nov 16, 2007 12:12 PM, Marc Garcia <[EMAIL PROTECTED]> wrote: > First one is about how to delete content in a FileField. With a > example: > > I've a model: > > class Person(model.Model): > name = models.CharField(maxlength=32) > [...] > picture = models.ImageField(upload_to='pictures', blank=True) > > Imagine that I've created a person record with a picture of anoother > person, and I want to delete it (the picture). How can I do? I think > that in admin it should be a checkbox for FileFields to remove > content.
The issue of deleting files stored with FileField is being addressed as part of #5361. It definitely won't be supported in the current admin, since all new admin work is being done on the newforms-admin branch, but I don't know if newforms-admin would support it or not. Even without incorporating it into the admin, deleting files will be much more straightforward once that work is complete. Expect more work on that to happen during the sprint in two weeks. > Second problem that I have. With an example as well. > > In last application I want my users to upload its own data, so I > create a page with a form generated with form_for_model for previous > model. > > When displayed, for a user that already exists, and already has a > picture, an empty <input type="file" ... /> is displayed for picture > field. User can't see it's own picture with admin's link, and when > saved, old picture is dropped. I think that it should work like in > admin (with delete checkbox). I think this is a matter for your view and template to handle. form_for_model and form_for_instance are just for convenience, they're not intended to give you full access to the model. In your case, you can use your model's get_FOO_url() method to get a URL for the image, then pass that to your template's context. Then, your template can either display a link, or even just display the image inline, if that's more suitable to your form. Again, the delete option would definitely not be available as part of the form, but it shouldn't be too hard to set up a view to delete the image, even without #5361 being included in trunk yet. Use get_FOO_filename() to get the absolute path to the file, and use Python's standard functions for dealing with it. -Gul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---
