Re: Django and uuid with PostgreSQL

2016-10-19 Thread Andrea Posi
Yes, it is actually correct, but I'd just like to force uuid generation at 
database level (postgres supports it) and not via python/django

I can modify the table with raw sql after migration and disable
default=uuid.uuid4
inside django models, but I'm looking for a better way to accomplish it

Il giorno mercoledì 19 ottobre 2016 02:14:23 UTC+2, Tim Graham ha scritto:
>
> The SQL looks correct -- it's not using anything Python related. Are you 
> encountering some error?
>
> On Tuesday, October 18, 2016 at 9:15:46 AM UTC-4, Andrea Posi wrote:
>>
>> I'm creating a rest api using Django and DRF. I don't want to expose IDs 
>> directly to clients so I'm trying to setup my models like this example:
>>
>> class AbstractGuidModel(models.Model):
>> uuid = models.UUIDField(blank=True, default=uuid.uuid4, unique=True, 
>> editable=False)
>>
>> class Meta:
>> abstract = True
>>
>> class MyModel(AbstractGuidModel):
>> name = models.CharField(max_length=NAME_LENGTH)
>>
>> Since the AbstractGuidModel has default=uuid.uuid4, uuid are generated by 
>> python code and migrations look like:
>>
>> CREATE TABLE "MyModel" ( ... "uuid" uuid NOT NULL UNIQUE, ... );
>>
>> I've read Postgres has an extension for generating automatically uuids.
>>
>> Once extension is installed, how can I tell django to let database use 
>> his own extension and not letting him create them with the Python uuid 
>> module?
>>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8c0630f1-eb24-4467-ba23-9eaeb1cb32cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django and uuid with PostgreSQL

2016-10-18 Thread Tim Graham
The SQL looks correct -- it's not using anything Python related. Are you 
encountering some error?

On Tuesday, October 18, 2016 at 9:15:46 AM UTC-4, Andrea Posi wrote:
>
> I'm creating a rest api using Django and DRF. I don't want to expose IDs 
> directly to clients so I'm trying to setup my models like this example:
>
> class AbstractGuidModel(models.Model):
> uuid = models.UUIDField(blank=True, default=uuid.uuid4, unique=True, 
> editable=False)
>
> class Meta:
> abstract = True
>
> class MyModel(AbstractGuidModel):
> name = models.CharField(max_length=NAME_LENGTH)
>
> Since the AbstractGuidModel has default=uuid.uuid4, uuid are generated by 
> python code and migrations look like:
>
> CREATE TABLE "MyModel" ( ... "uuid" uuid NOT NULL UNIQUE, ... );
>
> I've read Postgres has an extension for generating automatically uuids.
>
> Once extension is installed, how can I tell django to let database use his 
> own extension and not letting him create them with the Python uuid module?
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/29af39fa-b457-49c0-95d3-79bf70d95813%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django and uuid with PostgreSQL

2016-10-18 Thread Andrea Posi
I'm creating a rest api using Django and DRF. I don't want to expose IDs 
directly to clients so I'm trying to setup my models like this example:

class AbstractGuidModel(models.Model):
uuid = models.UUIDField(blank=True, default=uuid.uuid4, unique=True, 
editable=False)

class Meta:
abstract = True

class MyModel(AbstractGuidModel):
name = models.CharField(max_length=NAME_LENGTH)

Since the AbstractGuidModel has default=uuid.uuid4, uuid are generated by 
python code and migrations look like:

CREATE TABLE "MyModel" ( ... "uuid" uuid NOT NULL UNIQUE, ... );

I've read Postgres has an extension for generating automatically uuids.

Once extension is installed, how can I tell django to let database use his 
own extension and not letting him create them with the Python uuid module?

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/03ace98f-7bf3-4147-8ca4-17e5f6cf6f5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.