Changeset 9638 for src


Ignore:
Timestamp:
Aug 30, 2011, 8:18:09 PM (13 years ago)
Author:
rick
Message:

Files does not has to be unique.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/models.py

    r9637 r9638  
    55
    66from django.core import validators
     7from django.core.files.storage import FileSystemStorage
    78from django.db import models
    89from django.dispatch import receiver
    910from django.utils.encoding import smart_unicode
    1011from django.utils.translation import ugettext_lazy as _
     12
     13
     14# http://djangosnippets.org/snippets/976/
     15class OverwriteStorage(FileSystemStorage):
     16    def get_available_name(self, name):
     17        """
     18        Returns a filename that's free on the target storage system, and
     19        available for new content to be written to.
     20        """
     21        # If the filename already exists, remove it as if it was a true file system
     22        if self.exists(name):
     23            self.delete(name)
     24        return name
    1125
    1226class BinaryField(models.Field):
     
    142156class MeetBestand(models.Model):
    143157  meetrondje = models.ForeignKey(MeetRondje)
    144   bestand = models.FileField(upload_to='scan-data/%Y/%m/%d')
     158  bestand = models.FileField(upload_to='scan-data/%Y/%m/%d',storage=OverwriteStorage())
    145159  is_imported = models.BooleanField(default=False)
    146160  class Meta:
Note: See TracChangeset for help on using the changeset viewer.