This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Author(models.Model): | |
first_name = models.CharField(max_length=255) | |
last_name = models.CharField(max_length=255) | |
books = models.ManyToManyField('Book') | |
class Book(models.Model): | |
title = models.CharField(max_length=255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
book_store = BookStore.objects.get(name="B&N") | |
authors = Author.objects.filter(book__in=book_store.books.all()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models.fields.related import ReverseManyRelatedObjectsDescriptor | |
from django.db.models import ManyToManyField | |
class NewReverseManyRelatedObjectsDescriptor(ReverseManyRelatedObjectsDescriptor): | |
def make_id_list(self, obj): | |
through = self.field.rel.through | |
name = self.field.m2m_field_name() | |
related_name =self.field.m2m_reverse_field_name() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `author`.`id`, `author`.`first_name`, `author`.`last_name` | |
FROM `author` | |
INNER JOIN `author_books` | |
ON (`author`.`id` = `author_books`.`author_id`) | |
WHERE `author_books`.`book_id` | |
IN (SELECT U0.`book_id` FROM `bookstore_books` U0 WHERE U0.`bookstore_id` = 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `author`.`id`, `author`.`first_name`, `author`.`last_name` | |
FROM `author` | |
INNER JOIN `author_books` | |
ON (`author`.`id` = `author_books`.`author_id`) | |
WHERE `author_books`.`book_id` | |
IN (SELECT U0.`id` | |
FROM `book` U0 | |
INNER JOIN `bookstore_books` U1 | |
ON (U0.`id` = U1.`book_id`) | |
WHERE U1.`bookstore_id` = 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Author(models.Model): | |
first_name = models.CharField(max_length=255) | |
last_name = models.CharField(max_length=255) | |
books = models.ManyToManyField('Book') | |
class Book(models.Model): | |
title = models.CharField(max_length=255) | |
class BookStore(model.Model): | |
name = models.CharField(max_length=255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
book_store = BookStore.objects.get(name="B&N") | |
authors = Author.objects.filter(book__in=book_store.books.id_list()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="yourFancyBoxClass"> | |
{% if success %} | |
<h2>It Worked!</h2> | |
{% else %} | |
<form action="{% url ajax_form %}"> | |
{% form %} | |
</form> | |
{% endif %} | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpRepsonse | |
def first_post(request): | |
return HttpResponse('<h1>Hello World!</>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image | |
import cStringIO | |
import os | |
from django.core.files.base import ContentFile | |
from django.db.models import ImageField | |
from django.db.models.fields.files import ImageFieldFile | |
class JPEGFieldFile(ImageFieldFile): |
OlderNewer