I study Django 1.0.2 on Djangobook
Has read not all, but why that I can not find in this book the
information anywhere how to be with Image? In the book the example
with three models - Authors, Publisher and Books is resulted. And if I
want still the Image to books and that they were output in templates
in the identical sizes???
Prompt, please where to find such information
Here my code:
booksite/books/models.py
# -*- coding: utf-8 -*-
from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
def __unicode__(self):
return self.name
class Meta:
ordering = ['-name']
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField(blank=True, verbose_name='почта')
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author) # связь с данными из
таблицы Author
publisher = models.ForeignKey(Publisher) # Внешний ключ к таблице
Publisher
publication_date = models.DateField(blank=True, null=True)
def __unicode__(self):
return self.titlebooksite/books/views.py
booksite/books/views.py
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.shortcuts import render_to_response
from booksite.books.models import Publisher, Author, Book
def publisher(request):
pub = Publisher.objects.all()
return render_to_response('pub.html', {'pub': pub})
def archive(request):
bk = Book.objects.filter(title__contains="Dj")
return render_to_response('archive.html', {'bk': bk})
def index(request):
return render_to_response('index.html')booksite/books/templates/
pub.html
booksite/books/templates/pub.html
{% extends "base.html" %}
{% block title %}Книги{% endblock %}
{% block banner %}{% endblock %}
{% block content %}
{% for x in pub %}
<h1>{{ x.name }}</h1>
<p>{{ x.address }}</p>
<p>{{ x.website }}</p>
<hr/>
{% endfor %}
{% endblock %}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---