Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 15, 2011 19:07:37

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

booleanfield filter not working


Hi,

I have the following model:

class MerchantFormFields(models.Model):

merchant_form = models.ForeignKey(MerchantForms)
label = models.CharField(max_length=50)
field_type = models.ForeignKey(FieldTypes)
required = models.BooleanField()
dependency = models.BooleanField()
order = models.IntegerField()
attributes = JSONField()

and use the following method to query:

def get_form_fields(self, dependency=None, order='order'):

self.get_merchant_form()

filter = {}
filter = self.merchant_form

if dependency is not None:
filter = dependency

return
MerchantFormFields.objects.filter(**filter).order_by(order)

No matter if I specify False/True/0/1 I always get all the fields
associated with the merchant_form and not the dependency field. If I
print the filter before the query I can see the dependency filter is
set:

When dependency is False:
filter: {'merchant_form': <MerchantForms: MerchantForms object>,
'dependancy': False}

When dependency is True
filter: {'merchant_form': <MerchantForms: MerchantForms object>,
'dependancy': True}

Even if I look at the query formulated:

{
'time': '0.109',
'sql': u'SELECT `merchant_merchantformfields`.`id`,
`merchant_merchantformfields`.`merchant_form_id`,
`merchant_merchantformfields`.`label`,
`merchant_merchantformfields`.`field_type_id`,
`merchant_merchantformfields`.`required`,
`merchant_merchantformfields`.`dependancy`,
`merchant_merchantformfields`.`order`,
`merchant_merchantformfields`.`attributes` FROM
`merchant_merchantformfields` WHERE
(`merchant_merchantformfields`.`merchant_form_id` = 3 AND
`merchant_merchantformfields`.`dependancy` = 1 ) ORDER BY
`merchant_merchantformfields`.`order` ASC'
}

I can see the filter is correct. I've even run this query and have
seen the result I'm looking for but when I run it in my code, I get
all fields for the specified merchant_form...

I really don't know why this is.

Any help is greatly appreciated.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 15, 2011 19:11:26

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

booleanfield filter not working


And after I posted this...I figured out the issue. The problem lies in
the design of the class and how I was calling it...forgive me.

On Jan 15, 2:07 pm, deecodameeko <deecodame...@gmail.com> wrote:
> Hi,
>
> I have the following model:
>
> class MerchantFormFields(models.Model):
>
>     merchant_form      = models.ForeignKey(MerchantForms)
>     label              = models.CharField(max_length=50)
>     field_type         = models.ForeignKey(FieldTypes)
>     required           = models.BooleanField()
>     dependency         = models.BooleanField()
>     order              = models.IntegerField()
>     attributes         = JSONField()
>
> and use the following method to query:
>
> def get_form_fields(self, dependency=None, order='order'):
>
>         self.get_merchant_form()
>
>         filter = {}
>         filter = self.merchant_form
>
>         if dependency is not None:
>             filter = dependency
>
>         return
> MerchantFormFields.objects.filter(**filter).order_by(order)
>
> No matter if I specify False/True/0/1 I always get all the fields
> associated with the merchant_form and not the dependency field. If I
> print the filter before the query I can see the dependency filter is
> set:
>
> When dependency is False:
> filter: {'merchant_form': <MerchantForms: MerchantForms object>,
> 'dependancy': False}
>
> When dependency is True
> filter: {'merchant_form': <MerchantForms: MerchantForms object>,
> 'dependancy': True}
>
> Even if I look at the query formulated:
>
> {
>     'time': '0.109',
>     'sql': u'SELECT `merchant_merchantformfields`.`id`,
>     `merchant_merchantformfields`.`merchant_form_id`,
>     `merchant_merchantformfields`.`label`,
>     `merchant_merchantformfields`.`field_type_id`,
>     `merchant_merchantformfields`.`required`,
>     `merchant_merchantformfields`.`dependancy`,
>     `merchant_merchantformfields`.`order`,
>     `merchant_merchantformfields`.`attributes` FROM
> `merchant_merchantformfields` WHERE
> (`merchant_merchantformfields`.`merchant_form_id` = 3 AND
> `merchant_merchantformfields`.`dependancy` = 1 ) ORDER BY
> `merchant_merchantformfields`.`order` ASC'
>
> }
>
> I can see the filter is correct. I've even run this query and have
> seen the result I'm looking for but when I run it in my code, I get
> all fields for the specified merchant_form...
>
> I really don't know why this is.
>
> Any help is greatly appreciated.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support