> I have a project running in a manufacturing industry that is actually
> built upon django.
> In this I need to generate a unique serial, batch or lot number
> (depending on what you would like to call it) that is a running number
> from 0 to whathever for each and every day.
So when every day ticks over at midnight, the serial number starts at
zero again? Does production continue across the time 00:00? Why don't
you use a continuously increment number?
I don't know what the "right" thing to do is. I'm sure there will be a
classic solution. I think I would be writing a singleton function
nextnum() which returns the next number as required and then
lot_no = models.IntegerField(default=nextnum)
I'm not sure what would happen threadwise but a singleton would be a
natural place to deal with thread-locking and restarting the sequence
when the clock ticks over.
lot_no then gets the value prior to the save()
Mike
> There is a high risk of concurrency so just finding the previous max
> and then do a +1 before saving is not what I want.
> The important part of the model looks like this...
>
> class ProducedEntity(models.Model):
> ....
> production_date = models.DateField(auto_now_add=True)
> lot_no = models.PositiveIntegerField(default=0)
>
> class Meta:
> unique_together = ('production_date', 'lot_no')
>
> Of course I could just save it and see if the .save() call works
> without generating a IntegrityError but that's not elegant.
> Is there a way of generating that number per day in a way that it's
> done when I save the model?
>
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment