> Oleg Lomaka <...@gmail.com> :
>
>> Hm... Again I think I have answered this question already.
>> Book.objects.annotate(s_count=Count('sequences')).filter(s_count=0)
>
> Right, but if you're trying to get book by id, this is not an option.
> Again, you will need to query db twice.
>
Besides, sep
Oleg Lomaka <...@gmail.com> :
> Hm... Again I think I have answered this question already.
> Book.objects.annotate(s_count=Count('sequences')).filter(s_count=0)
Right, but if you're trying to get book by id, this is not an option.
Again, you will need to query db twice.
--
You received this me
Hm... Again I think I have answered this question already.
Book.objects.annotate(s_count=Count('sequences')).filter(s_count=0)
These are books, that doesn't belong to any sequence. And with one query
(though quite heavy query).
2011/5/1 А. Р. <4d876...@gmail.com>
>
> That's right. But if we hav
Oleg Lomaka <...@gmail.com> :
> We don't need the first query for fetching books. All data about book
> available from BookSequence too. And all filters you apply to books, you can
> apply to BookSequence via book__ filter. Again, from my first example, and
> using just one query
> bs =
> BookSeq
We don't need the first query for fetching books. All data about book
available from BookSequence too. And all filters you apply to books, you can
apply to BookSequence via book__ filter. Again, from my first example, and
using just one query
bs = BookSequence.objects.filter(book__title__startswit
Oleg Lomaka <...@gmail.com> :
> Sorry, but your question is too general as for me. Django doesn't support
> SQL joins directly. Could you specify with an example what data do you need
> to get from database using "joins"?
I just wonder if it is possible to get data from those three tables in
one
Sorry, but your question is too general as for me. Django doesn't support
SQL joins directly. Could you specify with an example what data do you need
to get from database using "joins"?
For example if you need to retrieve all books with zero associated sequences
(empty sequences list), then code s
2011/5/1 Oleg Lomaka <...@gmail.com>:
> bs = BookSequence.objects.filter(book__pk=1).select_related()
> for s in bs:
> print s.sequence.name, s.number_in_sequence
Oh, thanks!
Is it possible then to do left/right outer joins, as there may exist
books without
sequences and sequences without
bs = BookSequence.objects.filter(book__pk=1).select_related()
for s in bs:
print s.sequence.name, s.number_in_sequence
On Sun, May 1, 2011 at 1:30 PM, Alex <4d876...@gmail.com> wrote:
> Hello!
> Assume we have the following models:
>
>
> class Book(models.Model):
>title = models.CharFi
Hello!
Assume we have the following models:
class Book(models.Model):
title = models.CharField()
sequences = models.ManyToManyField(Sequence,
through='BookSequence')
class Sequence(models.Model):
name = models.CharField(unique=True)
class BookSequence(models.Model):
class Meta:
10 matches
Mail list logo