El mar., 11 de febrero de 2020 4:27 p.m., Mike Dewhirst <
[email protected]> escribió:

> On 11/02/2020 7:06 pm, Bruckner de Villiers wrote:
> >
> > Jason,
> >
> > Thank you.  I have changed the title of this mail.  If I have read the
> > 10 year old ticket 8576 correctly, it seems to be a DB restriction and
> > I imagine that there are good reasons for this.  However, then I don’t
> > understand the purpose of the AutoField given the restrictions and
> > that the Django documentation is somewhat ambiguous/vague.
> >
> > The options seem to be:
> >
> >   * Your uuid suggestion (which I have never worked with, but will
> >     explore)
> >   * a function in the model that does the incrementing before
> >     committing – (anyone have some example code for this?).  The
> >     challenge would be to keep track of the last used ticket no.  I
> >     haven’t thought this through yet, but it does occur to me that one
> >     could use the id (maybe prefix the id with some starting digits)
> >     and write the record twice. Probably barking up the wrong tree.
> >
>
> I have a need for a unique identifier in one of my models. I save the id
> to a separate field in the same model. In my case I don't need to see
> the value. It just needs to be unique and never change. It is used for
> generating the equivalent of a bar-code in a different model.
>
>      def save(self, *args, **kwargs):
>          if self.id:
>              if not self.formulation_no:
>                  self.formulation_no = str(self.id)
>          super().save(*args, **kwargs)
>
> A downside to this is the formulation number stays blank until the next
> save after creating the record. The upside is that the id isn't going to
> change so uniqueness isn't lost. Another way of doing this is to copy
> the id when it is first required and formulation_no is still blank.
>
> I have also been known to use a weird mechanism for user-resequencing
> records in a display. In that case they are lesson sequences within a
> course and question sequences within a lesson. I use floats and strings
> in a pair of fields so if that is of interest just ask.
>
> Cheers
>
> Mike
>
> >  *
> >
> > Regards,
> >
> > Bruckner de Villiers
> >
> > +27 83 625 1086
> >
> > *From: *<[email protected]> on behalf of Jason
> > <[email protected]>
> > *Reply to: *<[email protected]>
> > *Date: *Monday, 10 February 2020 at 14:55
> > *To: *Django users <[email protected]>
> > *Subject: *Re: Adding a verbose_name to id field
> >
> > Hmm.  TIL about https://code.djangoproject.com/ticket/8576
> >
> > Would a a uuid for this, rather than an integer?  If not, you'll have
> > to implement a save override to handle the incrementing yourself.
> >
> > In addition, it might be worthwhile bringing this ticket up for
> > discussion at https://groups.google.com/forum/#!forum/django-developers
> >
> > --
> > 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 [email protected]
> > <mailto:[email protected]>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/dc686528-0a8d-43ff-9973-d478cc765959%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/django-users/dc686528-0a8d-43ff-9973-d478cc765959%40googlegroups.com?utm_medium=email&utm_source=footer
> >.
> >
> > --
> > 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 [email protected]
> > <mailto:[email protected]>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/7C1BE52B-AFAE-4D38-9003-8A454A284A39%40gmail.com
> > <
> https://groups.google.com/d/msgid/django-users/7C1BE52B-AFAE-4D38-9003-8A454A284A39%40gmail.com?utm_medium=email&utm_source=footer
> >.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/99dbcba0-22bd-7c1d-5fe6-68984353bfb1%40dewhirst.com.au
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAGnT0hafj5viY5bYw5HioFxGX6dMgCc3yVSZ2CPA_DkqYS4sA%40mail.gmail.com.

Reply via email to