Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
ddd9ee16
Kaydet (Commit)
ddd9ee16
authored
May 18, 2013
tarafından
leandrafinger
Kaydeden (comit)
Marc Egli
May 18, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add missing imports to the examples in the 'First Steps'
üst
cd72c55d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
0 deletions
+29
-0
overview.txt
docs/intro/overview.txt
+4
-0
tutorial01.txt
docs/intro/tutorial01.txt
+2
-0
tutorial02.txt
docs/intro/tutorial02.txt
+16
-0
tutorial03.txt
docs/intro/tutorial03.txt
+5
-0
tutorial04.txt
docs/intro/tutorial04.txt
+2
-0
No files found.
docs/intro/overview.txt
Dosyayı görüntüle @
ddd9ee16
...
...
@@ -24,6 +24,8 @@ representing your models -- so far, it's been solving two years' worth of
database-schema problems. Here's a quick example, which might be saved in
the file ``mysite/news/models.py``::
from django.db import models
class Reporter(models.Model):
full_name = models.CharField(max_length=70)
...
...
@@ -214,6 +216,8 @@ Generally, a view retrieves data according to the parameters, loads a template
and renders the template with the retrieved data. Here's an example view for
``year_archive`` from above::
from django.shortcuts import render_to_response
def year_archive(request, year):
a_list = Article.objects.filter(pub_date__year=year)
return render_to_response('news/year_archive.html', {'year': year, 'article_list': a_list})
...
...
docs/intro/tutorial01.txt
Dosyayı görüntüle @
ddd9ee16
...
...
@@ -582,6 +582,8 @@ of this object. Let's fix that by editing the polls model (in the
``Choice``. On Python 3, simply replace ``__unicode__`` by ``__str__`` in the
following example::
from django.db import models
class Poll(models.Model):
# ...
def __unicode__(self): # Python 3: def __str__(self):
...
...
docs/intro/tutorial02.txt
Dosyayı görüntüle @
ddd9ee16
...
...
@@ -158,6 +158,9 @@ you want when you register the object.
Let's see how this works by re-ordering the fields on the edit form. Replace
the ``admin.site.register(Poll)`` line with::
from django.contrib import admin
from polls.models import Poll
class PollAdmin(admin.ModelAdmin):
fields = ['pub_date', 'question']
...
...
@@ -179,6 +182,9 @@ of fields, choosing an intuitive order is an important usability detail.
And speaking of forms with dozens of fields, you might want to split the form
up into fieldsets::
from django.contrib import admin
from polls.models import Poll
class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
...
...
@@ -198,6 +204,9 @@ You can assign arbitrary HTML classes to each fieldset. Django provides a
This is useful when you have a long form that contains a number of fields that
aren't commonly used::
from django.contrib import admin
from polls.models import Poll
class PollAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['question']}),
...
...
@@ -218,6 +227,7 @@ Yet.
There are two ways to solve this problem. The first is to register ``Choice``
with the admin just as we did with ``Poll``. That's easy::
from django.contrib import admin
from polls.models import Choice
admin.site.register(Choice)
...
...
@@ -342,6 +352,12 @@ representation of the output.
You can improve that by giving that method (in :file:`polls/models.py`) a few
attributes, as follows::
import datetime
from django.utils import timezone
from django.db import models
from polls.models import Poll
class Poll(models.Model):
# ...
def was_published_recently(self):
...
...
docs/intro/tutorial03.txt
Dosyayı görüntüle @
ddd9ee16
...
...
@@ -393,6 +393,9 @@ Now, let's tackle the poll detail view -- the page that displays the question
for a given poll. Here's the view::
from django.http import Http404
from django.shortcuts import render
from polls.models import Poll
# ...
def detail(request, poll_id):
try:
...
...
@@ -420,6 +423,8 @@ and raise :exc:`~django.http.Http404` if the object doesn't exist. Django
provides a shortcut. Here's the ``detail()`` view, rewritten::
from django.shortcuts import render, get_object_or_404
from polls.models import Poll
# ...
def detail(request, poll_id):
poll = get_object_or_404(Poll, pk=poll_id)
...
...
docs/intro/tutorial04.txt
Dosyayı görüntüle @
ddd9ee16
...
...
@@ -136,6 +136,8 @@ object. For more on :class:`~django.http.HttpRequest` objects, see the
After somebody votes in a poll, the ``vote()`` view redirects to the results
page for the poll. Let's write that view::
from django.shortcuts import get_object_or_404, render
def results(request, poll_id):
poll = get_object_or_404(Poll, pk=poll_id)
return render(request, 'polls/results.html', {'poll': poll})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment