On Mon, Mar 2, 2009 at 2:36 PM, limas <[email protected]> wrote:
>
> Hello.....
>
> my project deals with mnemonic-data pairs.
> so I have model like this:
>
> class DataValue(models.Model):
> file=models.ForeignKey(File)
> row=models.IntegerField()
> mnem=models.IntegerField()
> value=models.CharField(max_length=2000)
>
> class Curve(models.Model):
> file=models.ForeignKey(File)
> mnem=models.CharField(max_length=100)
>
> mnem field of DataValue contains the curve id, but it not set as the
> foreign key.
> so for each set of mnemonic data pairs for same file id i am trying to
> maintain row numbers.
>
> where i am failing is that ......
> i want to get a particular two mnemonic pairs.
> my query is like this:
>
> dataobj=DataValue.objects.filter(file=file.id).filter(mnem=1,mnem=2)
> where 1 and 2 are the curve ids for a particular condition.
>
> but i am getting only records corresponding to mnem=2.
>
> any valuable suggestions ? please help me......
> i think it might be some minor misunderstatnding.
>
> thanks in advanse
> Lima
>
>
> >
>
This is a bit about how Python works, when you do filter(mnem=1, mnem=2)
since the filter method takes **kwargs that translates that into a
dictionary {'mnem': 1, 'mnem': 2}, but wait, python dics don't have
duplicate keys, the last key wins, so it just because {'mnem': 2}. To fix
this you want to seperate it into 2 filter calls
filter(mnem=1).filter(mnem=2). But that still probably doesn't do what you
want, since you can't have a field which has 2 values at once, therefore I'm
guessing you want to OR them together,
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objectsis
probably what you want.
Alex
--
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---