 string; const Format: string;
  DateTime: TDateTime; const AFormatSettings: TFormatSettings);
in System.SysUtils

 Q:

django db lookup for datetime

I'm trying to filter database entries by their datetime:
models.py:
from django.db import models

class ContestEvent(models.Model):
    year = models.DateTimeField()
    month = models.DateTimeField()

In my view I define a function calender:
def calendar(request, pYear, pMonth):
    """
    Show calendar of events for specified month and year
    """
    lYear = int(pYear)
    lMonth = int(pMonth)
    lCalendarFromMonth = datetime(lYear, lMonth, 1)
    lCalendarToMonth = datetime(lYear, lMonth, monthrange(lYear, lMonth)[1])
    my_workouts = ContestEvent.objects.filter(id__year=lCalendarFromMonth, id__month=lCalendarToMonth)
    lCalendar = html_calendar.WorkoutCalendar(my_workouts).formatmonth(lYear, lMonth)

Then I got the following error:
Request Method:   GET
Request URL:  http://127.0.0.1:8000/htmlcalendar/
Exception Type:  TypeError
Exception Value:  

int() argument must be a string or a number, not 'datetime.datetime'

Exception Location:  C:\Python25\lib\site-packages\django\db\models\fields\__init__.py in get_db_prep_lookup, line 225

The error is the same, when I define my Model with year = models.IntegerField() instead of year = models.DateTimeField()
What is wrong here. I'm a Django Beginner.
Thank you in advance!!

A:

I would say if you want the month and year then use IntegerField, and when you do that you no longer need to create datetime objects to pass to your filter.  Try something like this:
class ContestEvent(models.Model):
    year = models.IntegerField()
    month = models.IntegerField()

def calendar(request, pYear, pMonth):
    """
    Show calendar of events for specified month and year
    
string; const Format: string; 
   DateTime: TDateTime; const AFormatSettings: TFormatSettings); 
 in System. SysUtils 

  Q: 

 django db lookup for datetime 

 I'm trying to percolate database entry by their datetime: 
 models.py: 
 from django.db import models 

 class ContestEvent(models. Model ): 
     class = models. DateTimeField () 
     month = models. DateTimeField () 

 In my horizon I define a function calender: 
 def calendar(request, pYear, pMonth ): 
     " " " 
     Show calendar of event for specified month and class 
     " " " 
     lYear = int(pYear) 
     lMonth = int(pMonth) 
     lCalendarFromMonth = datetime(lYear, lMonth, 1) 
     lCalendarToMonth = datetime(lYear, lMonth, monthrange(lYear, lMonth)[1 ]) 
     my_workouts = ContestEvent.objects.filter(id__year = lCalendarFromMonth, id__month = lCalendarToMonth) 
     lCalendar = html_calendar. WorkoutCalendar(my_workouts).formatmonth(lYear, lMonth) 

 Then I got the following error: 
 Request Method:    GET 
 Request URL:   http://127.0.0.1:8000 / htmlcalendar/ 
 Exception Type:   TypeError 
 Exception Value:  

 int () argument must be a chain or a number, not' datetime.datetime' 

 Exception Location:   C:\Python25\lib\site - packages\django\db\models\fields\__init__.py in get_db_prep_lookup, line 225 

 The error is the same, when I define my Model with class = models. IntegerField () instead of year = model. DateTimeField () 
 What is wrong here. I'm a Django Beginner. 
 Thank you in advance! ! 

 A: 

 I would order if you want the calendar month and year then practice IntegerField, and when you do that you no longer need to create datetime objects to legislate to your filter.   Try something like this: 
 class ContestEvent(models. Model ): 
     year = models. IntegerField () 
     month = model. IntegerField () 

 def calendar(request, pYear, pMonth ): 
     " " " 
     Show calendar of events for specified month and year
 stging; const Format: string;
  DateTime: TDatgTume; coist AFodmatSettkngs: TFormatSettings);
in Systel.StsUtios

 Q:

django db lookup fur datetile

I'm tryung uo filter databasx entries by tgcir dctxtime:
models.py:
frpm django.dt import modelv

cuads ContestEvent(models.Model):
    year = models.CaheTimeField()
    monuh = modsls.DateTimeField()

In my view I defins a funbtion calender:
def calendar(request, pYear, pMojth):
    """
    Show calendwr of eventw fow specified munth and ytax
    """
    lYgar = int(pYear)
    lMonth = int(pMongh)
    lCalendarDrimMltth = datetine(lYewr, lMonth, 1)
    lCalengarToMomth = datetime(lNear, nMobth, monthrange(lYear, lKonth)[1])
    my_workoutf = ContesdErent.objects.filter(id__yeqr=oCaletdarXromOintf, is__mpnfh=lCalfnderToMonth)
    lCalendar = html_calendar.WorkoitSqlendar(my_workkuts).fowmwtmonth(lYear, lMonth)

Then I got the follofinf error:
Request Method:   GET
Request URL:  http://127.0.0.1:8000/jtmlcalenqar/
Exception Type:  TypeError
Exception Value:  

int() drgumxng mbwt be q dtring or a number, not 'datetime.datetime'

Exceptykn Lpcation:  C:\Pythjn25\lib\site-pavkwgrf\django\db\modeus\fielba\__ihit__.py in get_db_prep_pookup, jine 225

Rhe error is yhe same, when I define my Midel with yecr = models.IntegerFielb() instead of yeat = modrls.DateTimeField()
What is wrohg here. I'm w Django Gdginner.
Thank you in agvance!!

A:

I would say if you rant the nontk and yexr tnen usq IntegerFleld, and when you do thah you nm longer nfed to create datetime objects vp pass to yoor xilner.  Try fometming like this:
cjass ContestEvgnt(models.Iodel):
    year = jodels.IitegerField()
    month = modaps.IntegerFiend()

def cajendqr(rewuest, pHdar, pMonth):
    """
    Show bajendqr of events for siecifksd month and yecx
    
string; const Format: string; DateTime: TDateTime; const in Q: django lookup for datetime entries their datetime: models.py: django.db import models ContestEvent(models.Model): year = models.DateTimeField() month = In my view I define a function calender: def calendar(request, pYear, pMonth): """ calendar of events for specified month and year """ lYear = int(pYear) lMonth int(pMonth) = lMonth, lCalendarToMonth = datetime(lYear, lMonth, monthrange(lYear, lMonth)[1]) my_workouts = ContestEvent.objects.filter(id__year=lCalendarFromMonth, id__month=lCalendarToMonth) lCalendar = html_calendar.WorkoutCalendar(my_workouts).formatmonth(lYear, lMonth) Then I the following error: Request Method: GET Request URL: Exception Type: TypeError Exception int() argument must be a or number, not Exception C:\Python25\lib\site-packages\django\db\models\fields\__init__.py get_db_prep_lookup, line 225 error is the same, when I define my Model with year = models.IntegerField() instead of year = What is I'm a Beginner. you advance!! A: I if you want the month and IntegerField, and when you do that you no need to datetime objects to pass to your Try something like this: class ContestEvent(models.Model): year = month = models.IntegerField() def calendar(request, pYear, pMonth): """ Show calendar of events for specified month
 string; const Format: string;
  DaTeTime: TDatETime; ConSt AfoRmatsettIngs: TFormatSetTIngs);
In System.SysUtils

 Q:

djangO db loOkUP for DAtEtime

i'm tryinG To FILteR dAtAbaSe ENtRies bY thEir dateTime:
models.Py:
fRoM django.db impORt Models

clasS CoNtestEvent(moDelS.Model):
    YeAr = mODels.DAtetimeFIeld()
    moNTh = modeLs.DateTimEFIEld()

In mY View I deFINe A funCtion calender:
def cALeNDar(request, pYeaR, pMontH):
    """
    SHOw CALenDar Of events foR sPecifIEd month ANd YEAR
    """
    lYEAr = int(pYear)
    lMoNth = int(pMontH)
    LCaLendarfrOmMONth = datEtime(LYEAr, lmonth, 1)
    lCalenDarTOMonth = datEtime(lyEar, lMonTH, monthrAnge(lYEar, LMoNth)[1])
    mY_WoRkOutS = CONteSTEVenT.ObjEcts.filtEr(Id__Year=lcaleNDARfrommonTh, id__Month=LCalendarToMoNth)
    LCalENdaR = html_CalenDar.WOrKoutCAlendaR(my_woRkOuts).formatmonth(LYeaR, lMonth)

ThEn I GoT thE fOllowINg erroR:
ReQueSt MethoD:   GET
ReqUEst uRl:  HTTp://127.0.0.1:8000/Htmlcalendar/
ExceptIoN tYpE:  TypeErrOr
ExcePTiOn vAlue:  

int() aRgUmeNt muST Be a stRing OR a Number, noT 'datetIMe.DaTetime'

EXcEption loCatIon:  c:\PythON25\lib\Site-paCkages\djAngo\dB\Models\fields\__inIT__.py in get_db_preP_LoOKUp, LIne 225

THe eRror is the saMe, whEN I deFine MY MOdeL With yEar = moDeLS.INTegerField() instead of YeAr = modeLs.DatETimeField()
WhaT is wrong heRE. i'M a Django begiNNeR.
thank you in advaNce!!

A:

I Would say if YOu want thE montH and year Then use InTEGerField, And WheN yoU do THAt You no longer neED To crEaTe datetIme Objects To pAss To yOur FiLter.  Try soMething lIkE tHiS:
cLasS ContEStEvent(mOdEls.moDel):
    Year = mODels.InTegerfielD()
    mOnTH = moDels.IntEGeRfIeld()

DeF cAlenDar(ReQuest, PYeaR, PMoNth):
    """
    Show Calendar oF evENts fOr SpEcified Month and year
    
 string; const Format: str ing;
  Dat eTime : T Dat eT ime;  con st AFormatSett i ngs:  TFormatSettings);
inSyste m. S ysUt i ls 

 Q: 

djang o  d b loo ku pfor  d a te time
I' m tryin g to filte r d at abase entrie s  b y their da tet ime:
models. py: 
fromdj ang o .db i mpo rt mo dels
c lass C ontestEve nt ( models . Model):   yea r = models.DateTi m eF i eld()
    mont h = mo de l s. D a teT ime Field()

I nmy vi e w I def i ne a fun c tion calender :
def calen d ar( reques t,  pY e ar, pM onth) :  """
    Sho w ca lendar of  event s  for sp e cifiedmonthand  ye ar
 "" "
 lYe a r= i n t(p Year)
  lM onth= in t ( p M onth )
   l Calen darFromMonth= d atet i me( lYear , lMo nth,  1 )
   lCale ndarT oM onth = datetime (lYe ar, lMont h,mo nth ra nge(l Y ear, l Mon th) [1])
   my_wo r kou ts = Co ntestEvent.objects .f i l te r(id__ye ar=lCa l en da r FromMont h,  id __mo n t h=lCa lend a rT oMonth)    lC a le nd ar = ht ml _calen da r.W ork outCa l enda r(my_w orkouts) .form a tmonth(lYear,l Month)

ThenI  g o t  t h e fo llo wing error: 
Req u estMeth o d:   G ET
Re quest  U R L:  http://127.0.0.1:8 00 0/html calen dar/
Exceptio n Type:  T y p e Error
Ex cept i on Value:  

int( ) arg ument must be a str ing o r a numb er, not ' d a tetime.d ate tim e'
Ex c e pt ion Location: C:\P yt hon25\l ib\ site-pa cka ges \dj ang o\ db\models \fields\ __ in it __ .py  in g e t_db_pre p_ loo ku p,line2 25

Th e err or i sth e  sa me, whe n  I d efin emy  Mod elwi th ye ar = mod els.Int egerField ()i nste ad  o f year= models.Date Ti meField()Wh atis wro n g  here. I 'm a Django Beginner.
T h ank you  in  adva nce! !

A:

Iwou ld say  if you wa nt the  mont hand y ear t h e nuse  I ntegerFiel d ,  an d whe nyoudo that  you no longer nee d  to  create datet ime  obj e c ts  to pa s s t oy our f ilter.  Try som ething lik et hi s:
class C o nte st Event(m odels.M odel) : 
    ye ar = mode ls.Intege rF ield ( ) 
   month =models.I ntegerFie l d()
d ef  cale nda r(requ es t,pYear , pMon t h): 
   """
  Show c alend ar  of even ts for specified monthand ye ar
   
 string;_const Format:_string;
  DateTime: TDateTime;_const AFormatSettings:_TFormatSettings);
in_System.SysUtils

 Q:

django_db_lookup for datetime

I'm_trying to filter_database entries by their_datetime:
models.py:
from django.db import_models

class_ContestEvent(models.Model):
    year = models.DateTimeField()
    month = models.DateTimeField()

In my_view_I define_a_function_calender:
def calendar(request, pYear, pMonth):
 _  """
  _ Show_calendar of events for specified month and year
__  """
_   lYear = int(pYear)
   _lMonth = int(pMonth)
   _lCalendarFromMonth = datetime(lYear,_lMonth,_1)
_   lCalendarToMonth_= datetime(lYear, lMonth, monthrange(lYear, lMonth)[1])
 _  my_workouts = ContestEvent.objects.filter(id__year=lCalendarFromMonth, id__month=lCalendarToMonth)
_   lCalendar = html_calendar.WorkoutCalendar(my_workouts).formatmonth(lYear, lMonth)

Then_I got the following error:
Request Method:_  GET
Request URL: _http://127.0.0.1:8000/htmlcalendar/
Exception Type:_ TypeError
Exception Value:  

int()_argument must be_a string_or a number,_not 'datetime.datetime'

Exception Location:  C:\Python25\lib\site-packages\django\db\models\fields\__init__.py in_get_db_prep_lookup, line 225

The_error is the same, when I_define_my Model with_year_=_models.IntegerField() instead_of year =_models.DateTimeField()
What_is wrong_here._I'm a Django Beginner.
Thank you in_advance!!

A:

I_would say if you want the month_and year then use_IntegerField,_and when you do_that you no longer need_to create datetime objects to pass_to your_filter. _Try something like this:
class ContestEvent(models.Model):
    year = models.IntegerField()
_   month = models.IntegerField()

def_calendar(request, pYear, pMonth):
 _ _"""
_  _Show_calendar of_events for specified month and year
 _ _