模型.py
class File(models.Model):
name = models.CharField(max_length=255)
src = models.FileField(upload_to="files")
class UserFile(models.Model):
user = models.ForeignKey(User)
files = models.ManyToManyField(File)
视图.py
def my_files(request):
user = request.user
myfile = UserFile.objects.filter(user=user)
return render_to_response('myfiles.html',context_instance=RequestContext(request))
如何获取属于当前登录用户的文件?