lukesneeringer / django-pgfields

Django field subclasses for some PostgreSQL types.
Other
68 stars 16 forks source link

Please add ability to use UUID1 algorithm for auto_add #4

Closed ghost closed 10 years ago

ghost commented 10 years ago

Currently uuid4 algorithm for auto_add=True is hardcoded in pre_save function:

class UUIDField(Field):
    """Field for storing UUIDs."""  

    ...

    def pre_save(self, instance, add):
        """If auto is set, generate a UUID at random."""

        # If the `auto_add` option was set, and there is no value
        # on the model instance, then generate a random UUID.
        if self._auto_add and add and not getattr(instance, self.attname):
            random_uuid = uuid.uuid4()

            # Save the UUID to the model instance
            setattr(instance, self.attname, random_uuid)
            return random_uuid

        # This is the standard case; just use the superclass logic.
        return super(UUIDField, self).pre_save(instance, add)

Please, add ability to use

uuid = models.UUIDField(verbose_name=_('UUID'), auto_add=True, unique=True, auto_add_algorithm=uuid.uuid1)

(but uuid4 is good to be by default

uuid = models.UUIDField(verbose_name=_('UUID'), auto_add=True, unique=True)

)

lukesneeringer commented 10 years ago

Hi @lorddaedra, Somehow I never saw this request. I'm going to check on my GitHub settings; I definitely don't want to ignore issues for four months.

I have no problem with this, and will get it in soon.

lukesneeringer commented 10 years ago

Hi @lorddaedra, Would you, at your convenience, please look over #7 and provide any feedback you may have? Thanks.