Is quering 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__(Google)
elif 'bing' in url:
return object.__new__(Bing)
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 [email protected].
To post to this group, send email to [email protected].
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/40054622-5cf8-4c42-a7f6-94681cb6d6e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.