A
A
Antigo_ptz2017-03-14 14:28:55
Django
Antigo_ptz, 2017-03-14 14:28:55

How to properly generate uuid in Django?

Hi everybody!
One of the models has a field of type UUIDField:

global_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)

The value is generated when a new record is created in the database.
But, there is one BUT. Data from the outside can be written directly to this table, bypassing my api.
Is there a chance that the global_id will be generated from the outside the same as the one I already generated earlier? A table can have tens of millions of records. Perhaps I need to change the generated value from uuid.uuid4 to some other version in this case. What do you advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-03-14
@Antigo_ptz

2.  Motivation

   One of the main reasons for using UUIDs is that no centralized
   authority is required to administer them (although one format uses
   IEEE 802 node identifiers, others do not).  As a result, generation
   on demand can be completely automated, and used for a variety of
   purposes.  The UUID generation algorithm described here supports very
   high allocation rates of up to <b>10 million per second per machine</b> if
   necessary, so that they could even be used as transaction IDs

https://tools.ietf.org/html/rfc4122.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question