Thursday, March 23, 2017

Querying performance

Is querying Provider model significantly less efficient using this pattern?

class Provider(models.Model):
    def __new__(cls, url, *args, **kwargs):
        if 'google' in url:
            return object.__new__(Ekino)
        elif 'bing' in url:
            print('gowno')

    url = models.CharField(primary_key=True)
    sth = models.CharField()

class Google(Provider):
def do_sth(self):
self.sth = 'sth'
self.save()

class Bing(Provider):
def do_sth(self):
self.sth = 'sth else'
self.save()

spam_url = 'https://www.google.pl/search?q=spam'
spam = Provider.objects.get_or_create(url=spam_url)
spam.__class__
<class '__main__.Google'>

eggs_url = 'https://search.yahoo.com/search;?p=eggs'
eggs = Provider.objects.get_or_create(url=eggs_url)
spam.__class__
<class '__main__.Yahoo'>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/34b6716e-180a-416a-91ea-33132af54be6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment