python - How to show only user uploads django -


how go showing user files upload (not all) i'm using python 2.7 , django 1.7 django allauth. below model. if can point me right direction thank you.

models.py

def hashed_uploads_dirs(instance, filename):     return os.path.join(instance.md5, filename)  class file(models.model):     f = models.filefield(upload_to='.')     md5 = models.charfield(max_length=32)     created_at = models.datetimefield(auto_now_add=true)     def was_published_recently(self):         return self.created_at >= timezone.now() - datetime.timedelta(days=1)     was_published_recently.admin_order_field = 'created_at'     was_published_recently.boolean = true     was_published_recently.short_description = 'published recently?'      def __unicode__(self):         return self.f.name      @models.permalink     def get_absolute_url(self):         return ('file-add', )  def save(self, *args, **kwargs):     self.slug = self.file.name     super(file, self).save(*args, **kwargs)    def delete(self, *args, **kwargs):     """delete -- remove leave file."""     self.file.delete(false)     super(file, self).delete(*args, **kwargs) 

you need modify file class store foreign key user. should like

... django.contrib.auth.models import user class file(models.model):     f = models.filefield(upload_to='.')     md5 = models.charfield(max_length=32)     created_at = models.datetimefield(auto_now_add=true)     user = models.foreignkey(user, related_name='uploaded_files') ... 

when upload file, you'll have set user before saving file. when have instance of user can uploaded files user.uploaded_files.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -