forked from zaxlct/imooc-django
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
__author__ = 'zaxlct' | ||
__date__ = '2017/4/6 下午12:14' | ||
|
||
import re | ||
|
||
from django import forms | ||
from operation.models import UserAsk | ||
|
||
|
||
# class UserAskForm(forms.Form): | ||
# name = forms.CharField(required=True, min_length=2, max_length=20) | ||
# phone = forms.CharField(required=True, min_length=11, max_length=11) | ||
# course_name = forms.CharField(required=True, min_length=5, max_length=50) | ||
|
||
|
||
class UserAskForm(forms.ModelForm): | ||
# 还可以新增字段 | ||
# price = forms.CharField(required=True, min_length=2, max_length=20) | ||
|
||
|
||
class Meta: | ||
model = UserAsk | ||
fields = ['name', 'mobile', 'course_name'] | ||
|
||
|
||
# def clean_name(self): | ||
# def clean_course_name(self): | ||
def clean_mobile(self): | ||
# 手机号验证 | ||
mobile = self.cleaned_data['mobile'] | ||
p = re.compile('^0\d{2,3}\d{7,8}$|^1[358]\d{9}$|^147\d{8}') | ||
if p.match(mobile): | ||
# 这里还能返回外键 | ||
return mobile | ||
raise forms.ValidationError('手机号码格式不对', code='mobile_inval') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
__author__ = 'zaxlct' | ||
__date__ = '2017/4/6 下午12:13' | ||
|
||
from django.conf.urls import url | ||
|
||
from .views import OrgView, AddUserAskView | ||
|
||
urlpatterns = [ | ||
#课程机构列表页 | ||
url(r'^list/$', OrgView.as_view(), name='org_list'), | ||
url(r'^add_ask/$', AddUserAskView.as_view(), name='add_ask'), | ||
|
||
# url(r'^home/(?P<org_id>\d+)/$', OrgHomeView.as_view(), name='org_home'), | ||
# url(r'^course/(?P<org_id>\d+)/$', OrgCourseView.as_view(), name='org_course'), | ||
# url(r'^desc/(?P<org_id>\d+)/$', OrgDescView.as_view(), name='org_desc'), | ||
# url(r'^teacher/(?P<org_id>\d+)/$', OrgTeacherView.as_view(), name='org_teacher'), | ||
# | ||
# # 课程机构收藏/取消收藏 | ||
# url(r'^add_fav/$', AddFavView.as_view(), name='add_fav'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters