On Tue, Mar 1, 2011 at 12:19 PM, Masklinn <maskl...@masklinn.net> wrote: > On 2011-03-01, at 12:11 , Marc Aymerich wrote: >> On Tue, Mar 1, 2011 at 12:02 PM, Daniel Hilton <daniel.hil...@gmail.com> >> wrote: >>> On 1 March 2011 10:55, Marc Aymerich <glicer...@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? >
Hi Masklinn, I never use jquey's :( My idea is that the end user can define their own arbitrary expression in order to match a subset of objects from a particular class. For example this is the class that handle the expression. class Service(models.Model): content_type = models.ForeignKey(ContentType) expression = models.CharField(max_length=255) price = models.PositiveIntegerField() So, with this class the admin of my application can say: Active .ORG domains costs 10€ , active .ES and .NET domains costs 25€ ... -- Marc -- 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 at http://groups.google.com/group/django-users?hl=en.