On Tue, Mar 1, 2011 at 2:07 PM, Marc Aymerich <glicer...@gmail.com> wrote: > On Tue, Mar 1, 2011 at 1:46 PM, Masklinn <maskl...@masklinn.net> wrote: >> On 2011-03-01, at 13:18 , Marc Aymerich wrote: >>> >>> Hi Masklinn, I never use jquey's :( >> Not a problem. The .is method simply takes a CSS selector and returns a >> boolean flag indicating whether the selected object(s) match the selector: >> $('a').is('a') is trivially going to return `true` for instance. >> >>> 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€ … >> But for that you should be able to use regular filters no? Build the right >> filtering kwargs (or a series of Q objects if you need arbitrary complexity, >> probably) from the stuff provided by the user and then call `filter` with >> that, and you should get the correct result shouldn't you? >> > > Hi, > what I want is a method for Service class that, given an object, > return their price. As far as I know I can't evaluate a queryset > against an object. Isn't it? >
Summarizing, I want to be able of: #Given a Domain instance domain = Domain.objects.get(pk=2) #Get their price price = Service.get_price(domain) class Domain(models.Model): active = models.BooleanField() root = models.CharField(max_length=6) class Service(models.Model): content_type = models.ForeignKey(ContentType) expression = models.CharField(max_length=255) price = models.PositiveIntegerField() @classmethod def get_price(cls, obj): ct = ContentType.objects.get_for_model(obj) for service in cls.objects.filter(content_type=ct): if service._expression_match(obj): return service.price def _expression_match(obj): """ This method evaluates the expression against obj """ I'm wondering what is the best way to implement _expression_match method :) thanks! -- 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.