> On Tue, Mar 1, 2011 at 12:02 PM, Daniel Hilton <daniel.hilton@gmail.com> wrote:
>> On 1 March 2011 10:55, Marc Aymerich <glicerinu@gmail.com> wrote:
>>> Hi!,
>>> I have a model class like this one:
>>>
>>> class Domain(models.Model):
>>> active = models.BooleanField()
>>> root = models.CharField(max_length=6)
>>>
>>> now given a Domain instance I need to know if it meets with an
>>> expresion like this one:
>>>
>>> active=True and (root='com' or root='net')
>>>
>>> one way to do that is get all domains that meets the expresion
>>> (formated as queryset) and check if the object is one of them.
>>> But maybe there is a more direct way to check it?
>>
>> You can use filter's with get so:
>>
>> Try:
>> myDomain = Domain.objects.get(active=True, etc...)
>> except myDomain.DoesNotExist:
>> myDomain = None
>>
>> Kinda like that ish.
>
> Hi Dan,
> Thanks for your answer! Unfortunately I need to do the inverse
> process, given an object I need to check if it meets with a
> 'queryset'.
Ah, so something equivalent to jQuery's `.is()` method? What kind of control do you have over the expression to test again? is it arbitrary as long as the semantics are the right ones or is its syntax already set in stone?
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment