本文整理汇总了Python中models.Build.brand方法的典型用法代码示例。如果您正苦于以下问题:Python Build.brand方法的具体用法?Python Build.brand怎么用?Python Build.brand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Build
的用法示例。
在下文中一共展示了Build.brand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_build
# 需要导入模块: from models import Build [as 别名]
# 或者: from models.Build import brand [as 别名]
def get_build(self):
""" Pre-fill some build attributes based on GET parameters """
build = Build(
forum_id = self.cleaned_data['forum_id'],
topic_id = self.cleaned_data['topic_id'],
user_id = self.request.user.id,
profile_id = self.request.user.get_profile().id,
title = self.cleaned_data['title'],
)
# create url
current_site = get_current_site(self.request)
build.url = "http://%s%s" % (current_site.domain, build.topic_url)
# Try to parse the scale
pattern = re.compile(r'1[:/](\d{1,4})')
match = re.search(pattern, build.title)
if match:
build.scale = match.group(1)
# see if we can match a brand...
bits = build.title.split()
for bit in bits:
brands = Brand.objects.filter(name__iexact=bit)
if brands:
build.brand = brands[0]
return build