本文整理汇总了Python中members.models.Member.gender方法的典型用法代码示例。如果您正苦于以下问题:Python Member.gender方法的具体用法?Python Member.gender怎么用?Python Member.gender使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类members.models.Member
的用法示例。
在下文中一共展示了Member.gender方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_file
# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import gender [as 别名]
def upload_file(request):
"""Creates a view to upload a file and read the contents, if the uploaded file is\
a zip file, file is first extracted and read. the file is read and updates the data\
to database. if the corresponding group is not present, a new group is created and updated."""
x = {}
y = []
s = []
if request.method == "POST":
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
title = form.files["file"]
filename = str(title)
x = request.FILES
front = filename.split(".")[0]
if filename.endswith(".zip"):
zipf = zipfile.ZipFile(x["file"])
zipf.extractall(os.getcwd())
else:
y = x["file"].read()
z = "" + front + ".xlsx"
path = default_storage.save(z, ContentFile(y))
tmp_file = os.path.join(settings.MEDIA_ROOT, path)
if form.is_valid():
workbook = xlrd.open_workbook(z)
sh = workbook.sheet_by_name("Sheet1")
for rownum in range(sh.nrows):
member = Member()
member.firstname = sh.row_values(rownum)[0]
member.lastname = sh.row_values(rownum)[1]
member.dob = sh.row_values(rownum)[2]
member.gender = sh.row_values(rownum)[3]
member.organisation = sh.row_values(rownum)[4]
member.email = sh.row_values(rownum)[5]
code = str(sh.row_values(rownum)[6])
group, status = Group.objects.get_or_create(group_code=code)
member.group = group
member.save()
os.chdir(os.getcwd())
files = glob.glob("*.xlsx")
for filename in files:
os.unlink(filename)
return HttpResponseRedirect(reverse("index"))
else:
form = UploadFileForm()
return render(request, "contacts/read.html", {"form": form})
示例2: member
# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import gender [as 别名]
def member(request):
"""Creates a view to add members to database, if the group code exists,\
add the user to that group or else create a new group and save."""
members = Member.objects.all()
groups = Group.objects.all()
if request.method == "POST":
form = MemberForm(request.POST)
if form.is_valid():
firstname = form.cleaned_data["firstname"]
lastname = form.cleaned_data["lastname"]
dob = form.cleaned_data["dob"]
gender = form.cleaned_data["gender"]
organisation = form.cleaned_data["organisation"]
email = form.cleaned_data["email"]
options = request.POST.getlist("group")
new_code = request.POST["new_group"]
name = request.POST["name"]
description = request.POST["description"]
try:
member = Member()
member.firstname = firstname
member.lastname = lastname
member.dob = dob
member.gender = gender
member.organisation = organisation
member.email = request.POST["email"]
grp_codes = [str(x) for x in options]
for cd in grp_codes:
if cd:
gr = Group.objects.get(group_code=cd)
member.group = gr
g, status = Group.objects.get_or_create(group_code=new_code)
g.name = name
g.description = description
member.group = g
member.save()
except:
pass
return HttpResponseRedirect(reverse("index"))
else:
form = MemberForm()
context = {"members": members, "groups": groups, "form": form}
return render(request, "members/member.html", context)
示例3: int
# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import gender [as 别名]
from groups.models import Group
t = int(raw_input('number of members you want to add:'))
import random, datetime
NAME_PREFIX = u'赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜'
NAME_SUFFIX = u'伟芳秀敏杰丹灵华兆婷超梁晗辉军越征凯腾江帆一中君盛丽群来未晨和刚明娜'
def get_rand(s):
return s[random.randint(0, len(s) - 1)]
groups = Group.objects.all()
for i in range(t):
m = Member()
m.balance = round(random.random() * 1000)
m.birthday = datetime.datetime.now() - datetime.timedelta(days=random.randint(0, 30000))
m.gender = get_rand(('M', 'F'))
m.group = get_rand(groups)
for t in range(0, 18):
m.identify_number += get_rand('0123456789')
m.name = get_rand(NAME_PREFIX) + get_rand(NAME_SUFFIX);
if random.randint(0, 2) == 1:
m.name += get_rand(NAME_SUFFIX)
m.point = random.randint(0, 200)
m.valid = bool(random.randint(0, 1))
m.valid_to = datetime.datetime.now() + datetime.timedelta(days=random.randint(0, 1000))
m.set_password('naiziylx')
m.save()
print m