Re: How to find out id of the first record?

2006-03-08 Thread PythonistL

Thank you all for help
L.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: How to find out id of the first record?

2006-03-08 Thread Andy Shaw

Andy Shaw wrote:
> lowest ID, or you can write a custom SQL query to do the same thing. I
> don't know if Django currently has a built-in feature to let you do
> this, though it is possible that the database will return the records in

Julio Nobrega wrote:
> first_record = models.get_list(order_by = ['id'], limit = 1)[0]
>
>   Maybe even .get_object() if it works with limit 1.

Laurent RAHUEL wrote:
> reqObs = something.get_list(order_by=('id',), limit=1)
> if reqObs:
>   firstOb = reqObs[0]

*slaps forehead* Naturally. Sorry, guys.

-Andy



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: How to find out id of the first record?

2006-03-08 Thread Laurent RAHUEL

Le Mercredi 8 Mars 2006 14:26, Andy Shaw a écrit :
> PythonistL wrote:
> > Hi,
> > is there a way how to find out id of the first record in a table?
> > I will explain what I mean.
> > When I insert the first record into a table the id is 1.
> > when I insert next record, the id for this record will be 2.
> > But if I delete the first record, the id of the first record will be 2
> > .So, I need to find out the id of the first record.
> > Is it possible?
> > Thank you for help
> > L.
>
> As the ID field is auto-incremented, the earliest ('first') record will
> be the one with the lowest ID. In python, you can determine this by
> pulling all records from the database and finding the one with the
> lowest ID, or you can write a custom SQL query to do the same thing. I
> don't know if Django currently has a built-in feature to let you do
> this, though it is possible that the database will return the records in
> creation order anyway (someone correct me here).
>
> -Andy
>

You can also use django "build-in" method on your model objects like :

reqObs = something.get_list(order_by=('id',), limit=1)
if reqObs:
  firstOb = reqObs[0]

Regards, Laurent.




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: How to find out id of the first record?

2006-03-08 Thread Julio Nobrega

  Something like this perhaps...

first_record = models.get_list(order_by = ['id'], limit = 1)[0]

  Maybe even .get_object() if it works with limit 1.



On 3/8/06, Andy Shaw <[EMAIL PROTECTED]> wrote:
>
> As the ID field is auto-incremented, the earliest ('first') record will
> be the one with the lowest ID. In python, you can determine this by
> pulling all records from the database and finding the one with the
> lowest ID, or you can write a custom SQL query to do the same thing. I
> don't know if Django currently has a built-in feature to let you do
> this, though it is possible that the database will return the records in
> creation order anyway (someone correct me here).
>
> -Andy


--
Julio Nobrega - http://www.inerciasensorial.com.br

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: How to find out id of the first record?

2006-03-08 Thread Andy Shaw

PythonistL wrote:
> Hi,
> is there a way how to find out id of the first record in a table?
> I will explain what I mean.
> When I insert the first record into a table the id is 1.
> when I insert next record, the id for this record will be 2.
> But if I delete the first record, the id of the first record will be 2
> .So, I need to find out the id of the first record.
> Is it possible?
> Thank you for help
> L.

As the ID field is auto-incremented, the earliest ('first') record will
be the one with the lowest ID. In python, you can determine this by
pulling all records from the database and finding the one with the
lowest ID, or you can write a custom SQL query to do the same thing. I
don't know if Django currently has a built-in feature to let you do
this, though it is possible that the database will return the records in
creation order anyway (someone correct me here).

-Andy

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



How to find out id of the first record?

2006-03-08 Thread PythonistL

Hi,
is there a way how to find out id of the first record in a table?
I will explain what I mean.
When I insert the first record into a table the id is 1.
when I insert next record, the id for this record will be 2.
But if I delete the first record, the id of the first record will be 2
.So, I need to find out the id of the first record.
Is it possible?
Thank you for help
L.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---