Monday, September 6, 2010

Re: Generate a daily serial/batch/lot number

On 6/09/2010 5:38 PM, kmpm wrote:
> On Sep 6, 9:02 am, Mike Dewhirst<mi...@dewhirst.com.au> wrote:
>> On 6/09/2010 4:19pm, kmpm wrote:
>>
>>> 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
>
>
> Yes it ticks over at midnight, and no there is no production at that
> time. More or less office hours only.
> A singleton would be nice but as you said it's not thread safe and
> won't scale nicely if we were to use multiple frontend servers or
> anything like that.

Then it would need to be a database trigger. At least in PostgreSQL you
could write it in the Python proc language supplied. It could create a
new temporary table with an incrementing column each night as a source
for the sequence number. That would cover occasional system stoppages
during the day.

I'm not sure how to integrate that in a nice way with django models
except as you alreadhy indicated with unique for date.

> There is a project called django-idmapper[1] that I just found that
> might solve it by using a model that seems to be stored in shared
> memory.
> If running on multiple frontends that would need to be something like
> memcached but I don't know about thread safety and concurrency there
> either.
>
>
> [1]http://github.com/dcramer/django-idmapper
>
>

--
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