As far as I can see, there are two approaches to take. One is to filter the results of the query in python (Note: I'm not talking about the filter method of querysets). The downside to this is that the database still returns all objects, and you are discarding those that having the wrong minute value. This may be acceptable if the table is small or the request is infrequent, but could be a performance pig otherwise. You can probably do this on a queryset with a generator expression to avoid pulling everything into memory at once. Where qs is a queryset with any other filters you need (or all) already applied::
for i in (for x in qs if x.datetimeField.minute == desired_minute): do something with i Or, you can add an additional where clause using the extra() method of querysets. This is more efficient, but you have to know how to specify the test in SQL, which may not be portable to other databases, and I can't promise that whatever database you are using knows how to take apart a timestamp object. It can take a while to get this stuff right, especially if there is a join involved, since you will have to figure out what django selected the appropriate table "AS". Bill On Sat, Feb 6, 2010 at 6:21 AM, jimgardener <jimgarde...@gmail.com> wrote: > hi > > I am a beginner with python and django and am writing my first > application.I need to retrieve some objects of my model class created > at different minutes in an hour.The class stores a datetime value in a > 'creationtime' ( DateTimeField )and have an associated 'subject' > string which can get repeated in many objects(ie object has one to > many relation with subject).Only the 'creationtime' is unique for an > object. > How can I get a unique object using MyModel.objects. get()? When I > checked the lookup docs ,it says it cannot do lookup on hour or > minute ,but only on year,month,day.. > Also I want to display the details of a single object.Do I need to > create a unique slug? Is it possible to create a slug from > DateTimeField 's value? (The prepopulated_fields in ModelAdmin doesn't > accept DateTimeField and ForeignKey ..so I am not sure if I can use it > in slug field). > Also, how should I create the get_absolute_url for the class? If > someone can give any pointers > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.