Re: iterate through list

2020-02-14 Thread Kai Kobschätzki
Thanks for the tip, I will read it :)

Greetings

bengoshi


On 2/14/20 2:31 PM, Roger Gammans wrote:
> No problem,
>
> It 's all explained here :
> https://docs.djangoproject.com/en/3.0/ref/models/querysets/
>
>
> On Fri, 2020-02-14 at 14:27 +0100, Kai Kobschätzki wrote:
>> Hi Roger:
>>
>> Thanks a lot! Such as easy :)
>>
>> Greetings
>>
>> bengoshi
>>
>>
>> On 2/14/20 2:15 PM, Roger Gammans wrote:
>>> Use:
>>>
>>> for data in Journal.objects.all():
>>> 
>>>
>>>
>>>
>>> On Fri, 2020-02-14 at 14:13 +0100, Kai Kobschätzki wrote:
 Hi:

 I want to do something with the content of a table. Problem is,
 that
 the
 IDs are not continuous. I tried:

 import .models from Journal

 last = Journal.obejects.last()
 last += 1
 for i in range(last):
   try:
 data = Journal.objects.get(pk=i)
 doing something with this data
   except:
 pass

 This solution runs but it seems not smart...

 I need the try because there a gaps in the table, so I have got
 e.g.
 element 1, element 3, element 8. If there is not an try/except
 the
 for
 will crash. And I need the last +=1 otherwise the last element
 won't
 be
 interpret.

 Could anyone show me how I could improve it?

 Thansk and Greetings

 bengoshi




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/921e32c0-33e7-aae5-bd7f-54b22a3f00f1%40gmail.com.


Re: iterate through list

2020-02-14 Thread Roger Gammans
No problem,

It 's all explained here :
https://docs.djangoproject.com/en/3.0/ref/models/querysets/


On Fri, 2020-02-14 at 14:27 +0100, Kai Kobschätzki wrote:
> Hi Roger:
> 
> Thanks a lot! Such as easy :)
> 
> Greetings
> 
> bengoshi
> 
> 
> On 2/14/20 2:15 PM, Roger Gammans wrote:
> > Use:
> > 
> > for data in Journal.objects.all():
> > 
> > 
> > 
> > 
> > On Fri, 2020-02-14 at 14:13 +0100, Kai Kobschätzki wrote:
> > > Hi:
> > > 
> > > I want to do something with the content of a table. Problem is,
> > > that
> > > the
> > > IDs are not continuous. I tried:
> > > 
> > > import .models from Journal
> > > 
> > > last = Journal.obejects.last()
> > > last += 1
> > > for i in range(last):
> > >   try:
> > > data = Journal.objects.get(pk=i)
> > > doing something with this data
> > >   except:
> > > pass
> > > 
> > > This solution runs but it seems not smart...
> > > 
> > > I need the try because there a gaps in the table, so I have got
> > > e.g.
> > > element 1, element 3, element 8. If there is not an try/except
> > > the
> > > for
> > > will crash. And I need the last +=1 otherwise the last element
> > > won't
> > > be
> > > interpret.
> > > 
> > > Could anyone show me how I could improve it?
> > > 
> > > Thansk and Greetings
> > > 
> > > bengoshi
> > > 
> > > 
> > > 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b7e3c940adeca708834de2d51620eb5b363767ac.camel%40gammascience.co.uk.


Re: iterate through list

2020-02-14 Thread Kai Kobschätzki
Hi Roger:

Thanks a lot! Such as easy :)

Greetings

bengoshi


On 2/14/20 2:15 PM, Roger Gammans wrote:
> Use:
>
> for data in Journal.objects.all():
>   
>
>
>
> On Fri, 2020-02-14 at 14:13 +0100, Kai Kobschätzki wrote:
>> Hi:
>>
>> I want to do something with the content of a table. Problem is, that
>> the
>> IDs are not continuous. I tried:
>>
>> import .models from Journal
>>
>> last = Journal.obejects.last()
>> last += 1
>> for i in range(last):
>>   try:
>> data = Journal.objects.get(pk=i)
>> doing something with this data
>>   except:
>> pass
>>
>> This solution runs but it seems not smart...
>>
>> I need the try because there a gaps in the table, so I have got e.g.
>> element 1, element 3, element 8. If there is not an try/except the
>> for
>> will crash. And I need the last +=1 otherwise the last element won't
>> be
>> interpret.
>>
>> Could anyone show me how I could improve it?
>>
>> Thansk and Greetings
>>
>> bengoshi
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/10f42748-2a92-3923-2d31-177e5f32563d%40gmail.com.


Re: iterate through list

2020-02-14 Thread Roger Gammans
Use:

for data in Journal.objects.all():




On Fri, 2020-02-14 at 14:13 +0100, Kai Kobschätzki wrote:
> Hi:
> 
> I want to do something with the content of a table. Problem is, that
> the
> IDs are not continuous. I tried:
> 
> import .models from Journal
> 
> last = Journal.obejects.last()
> last += 1
> for i in range(last):
>   try:
> data = Journal.objects.get(pk=i)
> doing something with this data
>   except:
> pass
> 
> This solution runs but it seems not smart...
> 
> I need the try because there a gaps in the table, so I have got e.g.
> element 1, element 3, element 8. If there is not an try/except the
> for
> will crash. And I need the last +=1 otherwise the last element won't
> be
> interpret.
> 
> Could anyone show me how I could improve it?
> 
> Thansk and Greetings
> 
> bengoshi
> 
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a1762f64afd90ca6ad1a28b6a10dc81af722c313.camel%40gammascience.co.uk.