Tuesday, May 26, 2020

Re: function model which generate a code for model field

Its not clear what you mean by "last"; do you mean a record that already exists in the database and has a ID value - or do you want the ID of the current record?  Either way, the code field should not be resetting the '0' to a '1' as this is then misrepresenting the actual data.

PS The logic to create the string looks a bit clunky; why not use rjust to get the correct number of prefix zeros?

On Monday, 25 May 2020 22:33:30 UTC+2, Anselme SERI wrote:
hello,
I am trying to create a function which will recover the last id of my model which I will increment and add to a character string, and I would like to add this new value (x = last id incremented + string) be added to the "code" field "of my model when I make a new recording.
How else could we use the id field which automatically increments to perform such an action?

Anselme S.

Le dim. 24 mai 2020 à 20:12, Kasper Laudrup <lau...@stacktrace.dk> a écrit :
Hi Anselme,

On 24/05/2020 17.48, Anselme SERI wrote:
>
> I try  to to write a correct function for my model which  generate a str
> + incremental number according last id model.
>

Your code is obviously wrong for quite a few reasons, but I at least
simply cannot understand what you are trying to achieve.

What should the "correct function" do?

The id field of a model is already incremental. Do you simply want to
append that to a string and what do you want to do with that string?

Kind regards,

Kasper Laudrup

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/65ffe493-1190-619a-f904-fbe35b60e3e3%40stacktrace.dk.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f8725fd3-bf12-4b82-b1d6-e8569d7220ff%40googlegroups.com.

No comments:

Post a Comment