For most recent N, try something like:

My_Model.objects.order_by("-id")[:N]

[This assumes that your database assures that primary keys increase
monotonically against creation order.  This is usual.  If you have an
unusual database in this regard, or if you wanted to limit how old an
item can be considered "Recently Added", you would need to add a
DateTimeField with auto_now_add set to True, and work with that.]


I still don't follow what you want for Most Common, but I'll guess
that you want, for example, an "Event" model that has a CharField,
called, for example "etype", and you want to know which value of etype
occurs most among the existing model instances.  There might be a way
to do this through the ORM, maybe using aggregate, annotate, etc., but
I'd be reaching for my SQL reference at this point to do a GROUP BY on
the etype field, then do a COUNT on the groups, then ORDER BY the
result of the COUNT, and finally LIMIT the result returned to 1.  The
exact syntax, whether things need to be set up as subqueries, and
behavior may vary depending on which database is used.  You should be
able to do this with "raw" queryset method, and you might be able to
do it with the "extra" queryset method, but you can always reach
around the ORM if needed.  The problem with some simpler approaches
through the ORM is that, if the table is large, you would like to
limit how many results are transferred from the database to django.

On 4/26/12, mohamed wagdy <m.wagdy2...@gmail.com> wrote:
> recently mean      N    added
>
> and
>
> most common      it  mean    the   N   object  that  the  person    used
>
>  say   .    i  make    an   event  system   and   i want  to  know
> most  common  event in  my  system
>
>
>
>
> On 4/26/12, Bill Freeman <ke1g...@gmail.com> wrote:
>> On 4/25/12, mohamed wagdy <m.wagdy2...@gmail.com> wrote:
>>>   please  i  want  a help
>>> ________________
>>>  I have some object stored  in     a  database    and i want  to
>>> make   List of this object  (Recently Added object -
>>> and
>>> Most Common)
>>
>> And I want a better description of what you are trying to do.
>>
>> For recently added, do you want the last N added, or do you want
>> those added within the last D days, or do you want a combination.
>>
>> I have no idea what you mean by "Most Common".
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@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.
>>
>>
>
>
> --
>      *   **mohamed wagdy *
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@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-users@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.

Reply via email to