Posts

How to use multiple model instances in views in django? -

i have created website when user upload image, detect objects on image , show them. here model: class document(models.model): docfile = models.filefield(upload_to='documents/%y/%m/%d') imgfile = models.filefield(upload_to='documents/%y/%m/%d',default='settings.media_root/default/default.jpg') catagory = models.charfield(max_length=100,default="unknow") the docfile original image, imgfile image label object in image, catagory category of object. my problem there might multiple objects in image, might have multiple document instances in views, don't know how many instances need in advance because depends on detection results. so how can implement this? , if can use document list in views, how can show contents in list in html template? thx. you can change models little: class baseimage(models.model): docfile = models.filefield(upload_to='documents/%y/%m/%d') class document(models.model): base_image =...

ruby on rails - Spec is failing on the same hour -

in app have few specs depend on distracting dates: survey_instance.created_at + 1.day then check if collection of survey_instances have proper size. specs fails @ 3 a.m. how can distract dates avoid problem? for problem, timecop invented! a gem providing "time travel" , "time freezing" capabilities, making dead simple test time-dependent code. provides unified method mock time.now, date.today, , datetime.now in single call. bundle , change spec like: timecop.freeze(2015, 10, 21, 10, 5, 0) # whatever assertion end this make sure test run @ same time of day.

android - Regain Focus on EditText when User Clicks It -

i have activity wiht edittext, , want following behaviour 1 of edittext: on activity starting-up, edittext populated text. should not show cursor, has no focus , not show keyboard (so user can read text , scroll , down). when user clicks/touches edittext, gain focus, show cursor , show keyboard (so user can start editing). the behaviour @ starting working ok, cannot "start editing" behaviour work when user clicks on edittext. here code: activity_main.xml: ... ... <edittext android:id="@+id/notepad" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.5" android:background="@android:color/transparent" android:textsize="@dimen/font_large" android:textstyle="normal" android:textcolor="@color/appprimarytext" android:textcolorhint="@color/appaccentco...

node.js - Push items into mongo array via mongoose -

i've scoured bit looking answer i'm sure i'm lost right words describe i'm after. basically have mongodb collection called 'people' schema collection follows: people: { name: string, friends: [{firstname: string, lastname: string}] } now, have basic express application connects database , creates 'people' empty friends array. in secondary place in application, form in place add friends. form takes in firstname , lastname , posts name field reference proper people object. what i'm having hard time doing creating new friend object , "pushing" friends array. i know when via mongo console use update function $push second argument after lookup criteria, can't seem find appropriate way mongoose this. db.people.update({name: "john"}, {$push: {friends: {firstname: "harry", lastname: "potter"}}}); update: so, adrian's answer helpful. following did in order accompli...

r - ggplot2 legend only showing partial border with legend.key attribute -

Image
i'm trying create graph using ggplot2, , don't understand why legend.key attribute placing border around part of legend. see minimal working example below. suggestions on fix? example provided here seems work fine ( https://github.com/hadley/ggplot2/wiki/legend-attributes#legendkey-rect ). set.seed(12) xy <- data.frame(x=c(rep(letters[1], times=25), rep(letters[2], times=25)), y=rep(letters[1:25], times=2), type = sample(c(-2,-1,0,1,2), 50, replace=t)) xy$type <- factor(xy$type, c(-2, -1, 0, 1, 2)) ggplot(xy, aes(x=x, y=y, fill=type, height=0.95)) + geom_tile() + scale_fill_manual(values = c("#323d8d", "#ffffff", "#ffffff", "#ffffff", "#ff0000"), na.value="#bebebe") + scale_x_discrete(expand=c(0,0.51)) + theme(legend.key = element_rect(colour="black")) + theme(axis.ticks.x = element_blank()) + theme(axis.ticks.y...

python - Django form wizard 'NoneType' object has no attribute 'rsplit' error -

hi hope can help, i've been trying out form wizard project , have been following documentation closely, keep getting error: 'nonetype' object has no attribute 'rsplit' forms.py: from django import forms class contactform1(forms.form): subject = forms.charfield() sender = forms.charfield() class contactform2(forms.form): message = forms.charfield() views.py: class contactwizard(wizardview): def done(self, form_list, **kwargs): return render_to_response('done.html', { 'form_data': [form.cleaned_data form in form_list], }) and urls.py (atestapp 'woo') urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^woo/', contactwizard.as_view([contactform1, contactform2])) ] traceback: environment: request method: request url: http://127.0.0.1:8000/woo/ django version: 1.8.4 python version: 3.4.0 installed applications: ('django.contrib.admi...

android - Opening Default Camera using Intent , overriding other apps? -

i trying open camera app, there other apps installed, such candy , retrica , phone asks 1 open. however, want open default camera, default in every devices. solution? here code: public void camerafuture(view view) { intent intent = new intent(android.provider.mediastore.action_image_capture); startactivityforresult(intent, 0); } protected void onactivityresult(int requestcode, int resultcode, intent data) { // todo auto-generated method stub super.onactivityresult(requestcode, resultcode, data); imageview iv = (imageview)findviewbyid(r.id.camtemp); bitmap bp = (bitmap) data.getextras().get("data"); iv.setimagebitmap(bp); } first of package name of camera want open default .(if need let know how this) just write code. change package name got camera - setpackage(" place new package name in here ") method intent mintent = null; mintent = new intent(); mintent.setpackage("com.sec.android.app.camera"); minte...