2

I want to display objects based on the datetime information they have. My model looks like this:

models.py

class Person(models.Model):
    name = models.CharField(max_length=50)

class Registration(models.Model):
    name = models.ForeignKey(Person)
    reg_id = models.IntegerField()
    reg_date = models.DateTimeField(db_index=True)
    reg_type = models.CharField(max_length=50)
    description = models.CharField(max_length-200)

urls.py

from app.models import Registration
from dajngo.views.generic.date_based import archive_day

queryset = registration.objects.all()


urlpatterns = patterns('',
    url(r'^$', 'ui.views.index'),
    url(r'^registrations/(?P<person_name>)\w+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', archive_day, {'year': year, 'month': month, 'day': day, 'queryset': queryset, 'date_field': reg_date})
)

)

My Intent:

I want to display all the registrations in a person's name, in a particular day. Yes, one person can have more than one registration.

I know I am wrong:

I read the docs, but it isn't much handy for a newbie like me. And while I figured out that their are these required parameters and some optional which need to be sent as a key: value pair. But what I don't seem to understand is that how can I reference the year, month, day, reg_time into the key: value pair of the dictionary. I mean to say, that obviously it wont recognize what year is right? So from where can I get the reference? Do I sound confused? I really am. Some help in clearing it will be much appreciated.

Update:

There's one thing I realize. The date is really going to be wrapped inside the request. Because the user is going to request that URL right? So probably I need to extract the values of year month and day from the request body.So how can this be done?

Indradhanush Gupta
  • 4,067
  • 10
  • 44
  • 60
  • add auto_now_add=True to your DateTimeField then for filtering see this question http://stackoverflow.com/questions/12176585/handling-dates-over-request-get – boltsfrombluesky Jun 25 '13 at 14:50

1 Answers1

0

Well it depends, if it's CBV then:

self.kwargs['year']

if it's the view function then:

def my_view(request, year, month, day):
    ...

https://docs.djangoproject.com/en/1.5/topics/http/urls/#notes-on-capturing-text-in-urls

mariodev
  • 13,928
  • 3
  • 49
  • 61