3 #Z@sddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z dd lmZdd lm Z d d Zd dZddZddZdS))render)formset_factory)ObjectDoesNotExist)HttpResponseRedirect)reverse) CaloriesForm)Calories)utils)modelscCs t|dS)Nz base.html)r)requestr E:\jaagup\tund\app1\views.pyindexsrc Cstt}|jdkrd|jkr||j}|jrg}x|D]x}|jjd}|jjd}|r8|r8t||r8t||d}ytj j|}Wnt k r|j |Yq8X||_ |j q8Wtj j|ttdS|tj jd} t|d| S)NPOSTZ submit_itemsfoodcalories) food_itemr)calories_formsetdataz calories.html)rrmethodris_valid cleaned_dataget no_duplicatesr objectsZObjectDoesNotExistsappendrsave bulk_createrrallr) r Zform_setrrformrrobjectentrycontextr r r calories_views*        r$cCs"x|D]}|jtjkrdSqWdS)NFT)rritem)rrr%r r rr-s  rcCsHtjtjdtjtjdtjjj}tjjj}t |dddiS)Nz-http://www.tlu.ee/~jankos/andmed/omanikud.txtz-http://www.tlu.ee/~jankos/andmed/raamatud.txtzmanyToManyTable.htmltitle manytomany) r Z save_omanikudZread_from_fileZ save_raamatudr omanikudrrraamatudr)r r(r)r r rmanyToManyTable3s  r*N)Zdjango.shortcutsrdjango.forms.formsetsrdjango.core.exceptionsr django.httpr django.urlsrformsrr r r rr$rr*r r r rs