You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
1.2 KiB

from django.utils import timezone
from pprint import pprint, pformat
import pydash as _; _.map = _.map_; _.filter = _.filter_
import random
def take(coll, n):
chunk = coll[0:n]
del coll[0:n]
return chunk
def take_random(coll, n):
if n == 0:
return []
chunk = _.sample(coll, n)
for item in chunk:
coll.remove(item)
return chunk
def take_one_random(coll):
if len(coll) == 0:
return None
return coll.pop(_.random(0, len(coll)-1))
def random_phone():
return '+7' + str(_.sample((917, 964, 965, 987, 912, 935))) + str(_.random(1000000, 9999999))
def random_date():
return timezone.datetime(_.random(2012, 2018), _.random(1, 12), _.random(1, 28))
def random_amount():
return random.random() * random.choice((100, 1000, 10000))
def model_fields(model, width=200):
pprint([(
f.name,
'Relation? %s' % f.is_relation,
'Null? %s' % f.null,
'Blank? %s' % f.blank if not f.is_relation else '(relation)',
'Hidden? %s' % (f.is_hidden() if hasattr(f, 'is_hidden') else False),
) for f in model._meta.get_fields(include_hidden=True)], width=width)