闲来无事,就自己看看Django,然后写个个人博客,尚未完成!以后会不断更新此博客的,完全开源,回头挂在Git上!
这是我的开发目录,很简单的一个个人博客
/blog/:
models.py
1 #!/usr/bin/env python 2 #coding=utf-8 3 from django.db import models 4 import datetime,time,os 5 from django.utils import timezone 6 from django.contrib.auth.models import User 7 8 # Create your models here. 9 10 class index_show(models.Model): 11 '''show_contents:内容,img_title:image title,img_path:image url''' 12 show_contents=models.TextField() 13 show_img_title=models.CharField(max_length=100) 14 show_img_path=models.FileField(upload_to=u'./xysite/static/upload') 15 #show_img_path=models.FileField(upload_to=handle_uploaded_file,null =True, blank=True) 16 #show_img_path=models.ImageField(upload_to='./xysite/static/upload',null =True, blank=True) 17 show_datetime=models.DateTimeField(default=datetime.datetime.now()) 18 def __unicode__(self): 19 return self.show_img_title 20 def was_published_recently(self): 21 return self.show_datetime >=timezone.now()-datetime.timedelta(days=1) 22 class blog_show(models.Model): 23 blog_title=models.CharField(max_length=200) 24 blog_contents=models.TextField() 25 blog_user=models.ForeignKey(User) 26 blog_datetime=models.DateTimeField(default=datetime.datetime.now()) 27 blog_img_title=models.CharField(max_length=100) 28 blog_img_path=models.FileField(upload_to='./xysite/static/upload/blog') 29 def __unicode__(self): 30 return self.blog_title 31 def was_published_recently(self): 32 return self.blog_datetime >=timezone.now()-datetime.timedelta(days=1) 33 34 ''' 35 def handle_uploaded_file(f): 36 file_name = "" 37 38 try: 39 path = "./xysite/static/upload" + time.strftime('/%Y/%m/%d/%H/%M/%S/') 40 if not os.path.exists(path): 41 os.makedirs(path) 42 file_name = path + f.name 43 destination = open(file_name, 'wb+') 44 for chunk in f.chunks(): 45 destination.write(chunk) 46 destination.close() 47 except Exception, e: 48 print e 49 50 return file_name 51 '''