class BitBucket models Model uploader models ForeignKey User upfile mo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class BitBucket(models.Model):
uploader = models.ForeignKey(User)
upfile = models.FileField(upload_to='bitbucket/')
pub_date = models.DateTimeField('date published', auto_now=1)
class Admin:
pass
class UploadForm(forms.ModelForm):
class Meta:
model = BitBucket
fields = ('upfile',)
def index(request):
form = UploadForm()
if request.POST:
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
instance = form.save(commit=False)
instance.uploader = request.user
instance.save()
return HttpResponseRedirect('/successful')
return direct_to_template(request, 'bitbucket/upload.html', {'form': form})
<form enctype="multipart/form-data" method="POST" action=".">
{{ form.as_p }}
<input type="submit">
</form>