这是我的第一个问题,所以我会感激耐心.
我从CharField将一些属性更改为IntegerField.下面列出的是代码:
rating_choices = (
(1,"1"),
(2,"2"),
(3,"3"),
(4,"4"),
(5,"5"),
)
class Rating(models.Model):
article = models.ForeignKey(Article,null=True)
organization = models.IntegerField(choices=rating_choices, default=1)
support = models.IntegerField(choices=rating_choices, default=1)
readability = models.IntegerField(choices=rating_choices, default=1)
tags = models.IntegerField(choices=rating_choices, default=1)
comments = models.TextField()
def get_overall_rating(self):
return fsum(self.organization + self.support + self.support + self.readability + self.tags)/5.0
overall_rating = property(get_overall_rating)
admin.site.register(Rating)
Run Code Online (Sandbox Code Playgroud)
我做了一个南迁移到Postgres迁移,这是我得到的错误:
Error in migration: collect_data:0010_auto__chg_field_rating_tags__chg_field_rating_support__chg_field_ratin
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in …Run Code Online (Sandbox Code Playgroud) 我在'tags'字段上实现了一个提升; 但是它没有以适当的方式对我的结果进行排名.
我的search_indexes.py:
class ParagraphIndex(indexes.SearchIndex, indexes.Indexable):
text= indexes.CharField(document=True, use_template=True, boost=1.0)
tags= indexes.MultiValueField(boost=2.5)
def prepare_tags(self,object):
return [tag.tag for tag in object.tags.all()]
Run Code Online (Sandbox Code Playgroud)
我的常规搜索适用于正确的字段.我已经多次运行update_index并仍然得到相同的答案.任何帮助都感激不尽.如果需要更多信息,请告诉我!
我对django有点新鲜.我试图在上传时选择将文件发送到另一台服务器,但form.is_valid()总是返回false会让我输入if
views.py-
def sent(request):
if request.method == 'POST':
form = SendFileForm(request.POST, request.FILES)
print "form is made"
print form.errors
if form.is_valid():
print "form is valid"
new_song = Song(songfile= request.FILES['songfile'])
new_song.save()
print "new song is made and saved"
l = List()
#cd = form.cleaned_data
#SENDS THE FILE TO SERVER GIVEN PATH
l.all_files(new_song.songfile.path)
return HttpResponseRedirect(reverse('get_files.views.sent'))
else:
print "form is not valid"
else:
form = SendFileForm()
songs = Song.objects.all()
return render_to_response('sent.html', {'songs': songs,'form': form}, context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
sent.html 模板-
{% if form.errors …Run Code Online (Sandbox Code Playgroud) 所以例如 -
//Functions
var validationCheck = function(req, res, next){
if(req.session.userId && req.session.token)
next('validationCatch') //Is this possible to skip middleware if not needed?
else
next()
}
var getUserId = function(req, res, next){
req.session.userId = DB.getUserId
next()
}
var getToken = function(req, res, next){
req.session.token = DB.getToken
next()
}
//a catcher function to direct to next function depending on route
var validationCatch = function(req, res, next){
next()
}
//Routes
app.get(api + '/feature1', validationCheck, getUserId, getToken, validationCatch, feature1)
app.get(api + '/feature2', validationCheck, getUserId, …Run Code Online (Sandbox Code Playgroud) django ×2
database ×1
django-forms ×1
django-south ×1
django-views ×1
express ×1
html ×1
javascript ×1
middleware ×1
node.js ×1