Giter Site home page Giter Site logo

django-shortuuidfield's Introduction

django-shortuuidfield

Provides a ShortUUIDField for your Django models which uses the base-57 "Short UUID" package at https://github.com/stochastic-technologies/shortuuid/ .

Originally, a fork from David Cramer's excellent django-uuidfield, but not much is left of that besides a bit of structure.

Installation

Install it with pip (or easy_install):

pip install django-shortuuidfield

Usage

First you'll need to attach a ShortUUIDField to your class. This acts as a char(22) to maintain compatibility with SQL versions:

from shortuuidfield import ShortUUIDField

class MyModel(models.Model):
    uuid = ShortUUIDField()

Enjoy!

Notes

  • ShortUUIDField is a subclass of django.db.models.CharField
  • You can pass usual Django CharField parameters on init, although some of them are added/overwritten:
    • max_length=22 (since we are using base-57 format which is fixed at 22 characters)
    • blank=True, editable=False (set auto=False to remove these fields enforcement)
  • Uses shortuuid.uuid() that generates uuid4 random values

django-shortuuidfield's People

Contributors

benrobster avatar clabra avatar dcramer avatar jezdez avatar mkouhei avatar mriveralee avatar pidelport avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-shortuuidfield's Issues

How fix problemm django.db.utils.IntegrityError: UNIQUE constraint failed?

My migration has the form
`# -- coding: utf-8 --

Generated by Django 1.9.2 on 2016-03-03 15:52

from future import unicode_literals

from django.db import migrations
import shortuuidfield.fields

class Migration(migrations.Migration):

dependencies = [
    ('patient', '0006_auto_20160226_0005'),
]

operations = [
    migrations.AddField(
        model_name='customer',
        name='uuid',
        field=shortuuidfield.fields.ShortUUIDField(blank=True, editable=False, max_length=22, unique=True),
    ),
]

`

When I try to run migrate myapp, I get the error
table patient_customer has no column named uuid

Default values not working

I've tried to create a new shortfield now a number of different ways. Using Django 2.2.5, Postgres 11 and version 0.1.3 of this library.

First I tried:

import shortuuid.uuid
class Organisation(models.Model):
    uuid = ShortUUIDField(default=shortuuid.uuid)

When migrating this fails with:

TypeError: uuid() missing 1 required positional argument: 'self'

So tried:

from shortuuid.main import uuid
class Organisation(models.Model):
    uuid = ShortUUIDField(default=uuid)

This works but all UUIDs in my database are the same

So tried without any default

from shortuuid.main import uuid
class Organisation(models.Model):
    uuid = ShortUUIDField()

and this predictably leaves the UUID field empty in the DB.

I tried adjusting my migrations a number of ways to get a proper random string, but no luck

How to make field case sensitive?

I have tried using django-shortuuidfield on a model, however when searched for the results are case insensitive, ie "9mgReChsS7kNmyTvRUYKtp" is the same as "9mgReChsS7kNmyTvRUYKtP".

This effectively changes the base-57 encoding to < base-36.

class Member(models.Model):
	id = ShortUUIDField(primary_key=True, db_index=True, max_length=22)
	…

Package via pip is Out of Date/Broken for Python 3

The python package available on via pip install django-shortuuidfield is an old version that is broken for python3. (Specifically all commits after and including the updated raised exception handling aren't reflected in the package.

   from shortuuidfield import ShortUUIDField
  File "/.../python3.4/site-packages/shortuuidfield/__init__.py", line 4
    except Exception, e:
                    ^
SyntaxError: invalid syntax

Steps to Repro:

  1. pip install django-shortuuidfield (https://pypi.python.org/pypi/django-shortuuidfield/0.1.2)
  2. Try to use the package on django + python3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.