def populate(num_opinions=None, product='mobile', type=None, locale=None): if not num_opinions: num_opinions = getattr(settings, 'NUM_FAKE_OPINIONS', DEFAULT_NUM_OPINIONS) else: num_opinions = int(num_opinions) if hasattr(type, 'id'): # Take "3" as well as OPINION_IDEA type = type.id for i in xrange(num_opinions): if not type: type = random.choice(TYPES).id o = Opinion(type=type, url=random.choice(URLS), locale=locale or random.choice(settings.INPUT_LANGUAGES), user_agent=random.choice(UA_STRINGS[product])) o.description = sample() if 'mobile': manufacturer = random.choice(DEVICES.keys()) o.manufacturer = manufacturer o.device = random.choice(DEVICES[manufacturer]) o.save(terms=False) o.created = datetime.datetime.now() - datetime.timedelta( seconds=random.randint(0, 30 * 24 * 3600)) o.save()
def populate(num_opinions=None, product='mobile', type=None, locale=None): models.signals.post_save.disconnect(extract_terms, sender=Opinion, dispatch_uid='extract_terms') if not num_opinions: num_opinions = getattr(settings, 'NUM_FAKE_OPINIONS', DEFAULT_NUM_OPINIONS) else: num_opinions = int(num_opinions) if hasattr(type, 'id'): # Take "3" as well as OPINION_IDEA type = type.id for i in xrange(num_opinions): if not type: type = random.choice(TYPES).id o = Opinion(type=type, url=random.choice(URLS), locale=locale or random.choice(settings.INPUT_LANGUAGES), user_agent=random.choice(UA_STRINGS[product])) o.description = sample() if 'mobile': manufacturer = random.choice(DEVICES.keys()) o.manufacturer = manufacturer o.device = random.choice(DEVICES[manufacturer]) o.save() o.created = datetime.datetime.now() - datetime.timedelta( seconds=random.randint(0, 30 * 24 * 3600)) o.save() models.signals.post_save.connect(extract_terms, sender=Opinion, dispatch_uid='extract_terms')