Django1.0 수정 후 내용
django 1.02 Admin ,google , django 。
Django Step by Step 1.0.2 참조
The new tutorial is not finished yet.
urls.py
:
from
django.conf.urls.defaults import
*
urlpatterns = patterns('',
(r'^admin/
', include('django.contrib.admin.urls
'),
)
Django1.0 :
from
django.conf.urls.defaults import
*
from
django.contrib import
admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/(.*)
', admin.site.root),
)
=========================================================================
models.py
:
class
MyTag
(models.Model):
name = models.CharField(blank=True, max_length=100)
class
Meta
:
verbose_name = 'MyTag
'
verbose_name_plural = 'MyTag
'
class
Admin
:
pass
def
__unicode__
(self):
return
self.name
class
MyEntry
(models.Model):
title = models.CharField(blank=True, max_length=100)
content = models.TextField(blank=True)
pub_date = models.DateTimeField(blank=True, default=datetime.datetime.now)
tags = models.ManyToManyField(MyTag, blank=True)
class
Meta
:
verbose_name = 'Entry
'
verbose_name_plural = 'Entries
'
ordering = ['-pub_date
']
class
Admin
:
list_display = ['title
', 'pub_date
']
search_fields = ['title
', 'content
']
js = ['/static/js/customize.js
']
def
__unicode__
(self):
return
self.title
Django1.0 :
class
MyTag
(models.Model):
name = models.CharField(blank=True, max_length=100)
class
Meta
:
verbose_name = 'MyTag
'
verbose_name_plural = 'MyTag
'
def
__unicode__
(self):
return
self.name
class
MyEntry
(models.Model):
title = models.CharField(blank=True, max_length=100)
content = models.TextField(blank=True)
pub_date = models.DateTimeField(blank=True, default=datetime.datetime.now)
tags = models.ManyToManyField(MyTag, blank=True)
class
Meta
:
verbose_name = 'Entry
'
verbose_name_plural = 'Entries
'
ordering = ['-pub_date
']
def
__unicode__
(self):
return
self.title
admin.py
from
django.contrib import
admin
from
models import
MyTag, MyEntry
class
MyEntryAdmin
(admin.ModelAdmin):
list_display = ['title
', 'pub_date
']
search_fields = ['title
', 'content
']
class
Media
:
js = ['/static/js/customize.js
']
admin.site.register(MyTag)
admin.site.register(MyEntry, MyEntryAdmin)
======================================
forms
:
from
django import
newforms as
forms
Django1.0 :
from
django import
forms
======================================
models.py
class
MyModel
(models.Model):
myphoto = models.ImageField(upload_to="img/uploads
")
:
myinstance = MyModel.objects.all()[0]
photo_url = myinstance.get_myphoto_url()
Django1.0 :
myinstance = MyModel.objects.all()[0]
photo_url = myinstance.myphoto.url
======================================
Forms:
class
MyUploadForm
(forms.Form):
target_file = forms.FileField(widget=forms.FileInput)
:
form = MyUploadForm(request.POST, request.FILES)
if
form.is_valid():
target_file = form.cleaned_data['target_file
']
f = open(target_file.filename, 'wb
')
f.write(target_file.content)
Django1.0 :
form = MyUploadForm(request.POST, request.FILES)
if
form.is_valid():
target_file = form.cleaned_data['target_file
']
f = open(target_file.name, 'wb
')
for
chunk in
target_file.chunks():
f.write(chunk)
f.close()
======================================
Signal
:
from
django.db.models.signals import
pre_save
from
django.dispatch import
dispatcher
def
update
(signal, sender, instance, **kwds):
instance.pub_date = datetime.datetime.now()
dispatcher.connect(update, pre_save, MyEntry)
Django1.0 :
from
django.db.models.signals import
pre_save
def
update
(signal, sender, instance, **kwds):
instance.pub_date = datetime.datetime.now()
pre_save.connect(receiver=update, sender=MyEntry)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Django의 질문 및 답변 웹사이트환영 친구, 이것은 우리의 새로운 블로그입니다. 이 블로그에서는 , 과 같은 Question-n-Answer 웹사이트를 만들고 있습니다. 이 웹사이트는 회원가입 및 로그인이 가능합니다. 로그인 후 사용자는 사용자의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.