Hi

I've been learning to love django lately, but I can't quite wrap my
head around more advanced querysets.  I've listed my classes and their
sql tables on the bottom, as all problems are linked to those tables.

First problem:
I have a class, Content, with a set of tags,  how can I filter for
multiple tags?
If I do:
list = Content.objects.filter(tag__id=1).filter(tag__id=2) it makes a
sql query asking content_content_tags for content_id's where tag_id = 1
and tag_id = 2, which will of course never match.

What I'd like to do is something like:
for tag in request.GET.getlist('tag')
        content = content.filter('match this tag too')



Second problem:
I've looked at complex_filter for doing this and I can't quite figure
it out.
What if I wanted something like this:
content.objects.filter(id__id=1) | content.objects.filter(id__id=2)
But I needed to match a dynamic list of id's.  How could I do something
like

content = content.objects.filter(content=example)
for match in id_list:
        content = content.objects.filter(id__id=match) #And here get a logical
OR comparison with the previus part of the loop.
So this would produce the same effect as:
content.objects.filter(id__id=id_list[0]) |
content.objects.filter(id__id=id_list[1])



Third problem: (promise I'm done soon :p )
And this is something I can't quite wrap my head around.  I want to
allow each individual user to sort by percentage of files seen.
Sorting content that is.
So I want to produce a list of Content, but sort it based on the
percentage of FileName objects in that content category the user has
seen.

I'm thinking I'll need to override the save() function in FileName, and
update the percentage, stored in a different table.  But since this
percentage has to be stored per user, and I somehow have to sort
content by it I dont have a foggy clue how to make my classes.
Does something like this make sense: (where it's updated on
FileName.save())
class SeenCache(models.Model):
        content = models.ForeignKey('Content')
        user = models.ForeignKey(User)
        percentage = models.IntegerField()
It'd only work if a user has seen one file in that category though.




Classes:
class Tag(models.Model):
        name = models.CharField(maxlength=20)

class FileName(models.Model):
        fullname = models.CharField(maxlength = 1024,core=True)
        content = models.ForeignKey('Content')
        #List of users that has seen this content
        users_seen =
models.ManyToManyField(User,core=True,null=True,blank=True)

class Content(models.Model):
        name = models.CharField(maxlength = 200,null=True,blank=True)
        tags = models.ManyToManyField(Tag,null=True,blank=True)



Produced sql tables:
CREATE TABLE "content_content" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(200) NULL,
);
CREATE TABLE "content_content_tags" (
    "id" integer NOT NULL PRIMARY KEY,
    "content_id" integer NOT NULL REFERENCES "content_content" ("id"),
    "tag_id" integer NOT NULL REFERENCES "content_tag" ("id"),
    UNIQUE ("content_id", "tag_id")
);
CREATE TABLE "content_filename" (
    "id" integer NOT NULL PRIMARY KEY,
    "fullname" varchar(1024) NOT NULL,
    "content_id" integer NOT NULL REFERENCES "content_content" ("id")
);
CREATE TABLE "content_filename_users_seen" (
    "id" integer NOT NULL PRIMARY KEY,
    "filename_id" integer NOT NULL REFERENCES "content_filename"
("id"),
    "user_id" integer NOT NULL REFERENCES "auth_user" ("id"),
    UNIQUE ("filename_id", "user_id")
);
CREATE TABLE "content_tag" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(20) NOT NULL,
);


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to