ManyToMany fields in database lookups

0 views
Skip to first unread message

Vincent Foley

unread,
Mar 4, 2008, 10:28:12 AM3/4/08
to Django users
Hello,

I have a curious problem with a complex filter in 0.96:

Merchant.objects.filter(Q(categories_fr__name__icontains=s) |
Q(categories_en__name__icontains=s))

this returns an empty queryset even when 's' is in categories_fr.
Changing categories_fr__name with an attribute directly in the object
has the same effect. It seems that a ManyToMany field with no
elements nullifies the entire query.

Is this a bug, or am I misunderstanding something?

Thank you,

Vincent.

Malcolm Tredinnick

unread,
Mar 4, 2008, 11:19:35 AM3/4/08
to django...@googlegroups.com

There are a few issues with many-to-many fields and empty results like
this. The whole area has been given an overhaul in the queryset-refactor
branch and so should be fixed on trunk soon-ish.

In the meantime, just select the two halves individually and merge them
in Python.

Malcolm

--
If it walks out of your refrigerator, LET IT GO!!
http://www.pointy-stick.com/blog/

Phillip Watts

unread,
Mar 4, 2008, 1:18:57 PM3/4/08
to django...@googlegroups.com
I can't figure out where to put css files or background images referred to by
css. I have:

<link rel="stylesheet" href="dirview.css" type="text/css">
and
MEDIA_ROOT = '/home/phil/philproj/media/'

ls -al /home/phil/philproj/media
total 12
drwxr-xr-x 2 phil phil 4096 2008-03-04 11:57 .
drwxr-xr-x 7 phil phil 4096 2008-03-04 12:14 ..
-rw-r--r-- 1 phil phil 96 2008-03-04 11:57 dirview.css

I've tried everything? Help? Thanks

Lewis Bergman

unread,
Mar 4, 2008, 1:38:25 PM3/4/08
to django...@googlegroups.com
Where are your templates stored?

Evert Rol

unread,
Mar 4, 2008, 2:30:37 PM3/4/08
to django...@googlegroups.com
> I can't figure out where to put css files or background images
> referred to by
> css. I have:
>
> <link rel="stylesheet" href="dirview.css" type="text/css">
> and
> MEDIA_ROOT = '/home/phil/philproj/media/'

Don't you need a '/media/' or something before that 'dirview.css'?
What is your MEDIA_URL?
Since Django normally has the media files (css, images etc) served
completely separately, relative paths to media files don't really work.


Btw, be careful when starting a new subject by replying to an old
thread: you've just hijacked another thread, see http://groups.google.com/group/django-users/browse_thread/thread/92052a98c16509a0?hl=en
Better start a new thread/message/question from scratch.

Phillip Watts

unread,
Mar 4, 2008, 3:34:35 PM3/4/08
to django...@googlegroups.com, Lewis Bergman
On Tuesday 04 March 2008 12:38:25 Lewis Bergman wrote:
> Where are your templates stored?

currently, here
TEMPLATE_DIRS = (
'/home/philproj/dirview/httemplates',)
but I have copies of dirview.css in that any every
other directory I could think of accessible to user phil.

And, oh yeah, no slash on the end. That's inconsistent
with other settings like MEDIA_ROOT.

Brian Luft

unread,
Mar 5, 2008, 2:37:58 PM3/5/08
to Django users
Serving static media really has nothing to do with Django. Presumably
your browser is reading the CSS file and making a request back to your
web server for the file. You haven't told us anything about your web
server configuration. What path is being requested to the server for
the image file? How is your web server handling that request?

If you're using the development server, was there anything in the
serving static media FAQ that you did not understand?
> > > I've tried everything? Help? Thanks- Hide quoted text -
>
> - Show quoted text -

Phillip Watts

unread,
Mar 5, 2008, 7:53:13 PM3/5/08
to django...@googlegroups.com
On Wednesday 05 March 2008 13:37:58 Brian Luft wrote:
> Serving static media really has nothing to do with Django.

Funny that css and js are considered "static media". In the spirit
of templating they should be dynamic. I would characterize them as
junk_patched_on_to_a_crappy_platform. But, Oh well.

> Presumably
> your browser is reading the CSS file and making a request back to your
> web server for the file. You haven't told us anything about your web
> server configuration. What path is being requested to the server for
> the image file? How is your web server handling that request?
>
> If you're using the development server, was there anything in the
> serving static media FAQ that you did not understand?

Therein lies the problem. I don't want to have one set of code for
the development server and another for ?. E.g., django code which
works for sqlite works for MySQL.

I think I will explore using the template loader more creatively and
possibly recursively to produce inline css and js.

Thanks for all help.

Brian Luft

unread,
Mar 5, 2008, 9:38:01 PM3/5/08
to Django users
> Funny that css and js are considered "static media". In the spirit
> of templating they should be dynamic.

I'm not quite sure what you mean. Typically the contents of CSS,
Javascript, and image files don't change from request to request.
Hence - "static media". In most cases requests for "static media" are
handled by the web server simply returning the contents of requested
media directly from a file on disk. I'm not saying there aren't valid
cases for dynamically generating CSS, Javascript or even images, but
this is far less common than the well-accepted paradigm of separating
these resources from the application source entirely. You'd better
come up with some pretty hefty processing power and memory if you're
going to be handling each request for a page resource (of which there
may be dozens) with the interpreter rather than falling back on the
highly optimized web-server itself.

> Therein lies the problem. I don't want to have one set of code for
> the development server and another for ?. E.g., django code which
> works for sqlite works for MySQL.

You may have been confused by what I said or vice versa. Django is
one of many cross-platform web frameworks out there. (Well, Django
itself isn't inherently cross-platform. It runs on Python which is
and the developers thankfully had the wisdom not to put any platform-
specific dependencies into their implementation). Taking your example
- the Django ORM supports multiple databases. What this means is that
you code your schema and application logic against the Django Models
and DB API, and you can run the same code against any of the databases
Django supports. More generally, you can run the same Django code on
any platform that supports Python 2.3+. I have a Windows development
box but I run my production sites on Linux - it's the exact same code
everywhere. Development wouldn't be very fun if you had to keep track
of machine or OS specific bits for all the places your code might run.

> I think I will explore using the template loader more creatively and
> possibly recursively to produce inline css and js.

I don't know exactly what problem you are trying to tackle. Again,
there may be perfectly valid reasons why you are trying to adopt this
type of strategy, but a strategy like this has serious implications
for the future scalability and maintenance of your application. This
user group and community are very helpful. If you can describe more
about what you are trying to architect you'll get a lot of great
pointers about best practices and the best manner in which to leverage
the strengths of the framework.

-Brian
Reply all
Reply to author
Forward
0 new messages