jbrendel / django-randomprimary Goto Github PK
View Code? Open in Web Editor NEWRandom looking primary keys for Django models
Random looking primary keys for Django models
Django 1.4
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/link/link/add/
Django Version: 1.4
Exception Type: ValueError
Exception Value:
invalid literal for int() with base 10: 'AGw62'
Exception Location: C:\Python27\lib\site-packages\django\db\models\fields__init__.py in get_prep_value, line 537
Python Version: 2.7.3
I have changed id = models.CharField to id = models.AutoField
To my understanding this is because somewhere a string is passed where only a integer can be passed. In my views I'm using render_to_response, get_object_or_404, RequestContext. Are there any limitations? I have also tried applying RandomPrimaryIdModel instead of models.Model in the Poll class created in the official Django tutorial for Django 1.4 (https://docs.djangoproject.com/en/1.4/intro/tutorial01/) and it raises the same error.
Just occurred to me - these are going in your urls, and you never know what you might spell at random.
Seriously, leaving out the vowels would probably avoid this issue, with fairly small cost in reducing the key space.
Hello and thanks for your awesome model. The only issue I found after a considerable amount of debugging was that it behaves slightly differently to an AutoField: AutoFields appear to have blank=True by default, so that they (correctly) are not required to be set in forms. RandomPrimaryIdModel has blank=False, which generates an "xxx is required" error on form submission and prevents automatic key generation. I would suggest changing this section
id = models.CharField(db_index = True,
primary_key = True,
max_length = CRYPT_KEY_LEN_MAX+1+len(KEYPREFIX)+len(KEYSUFFIX),
unique = True)
to
id = models.CharField(db_index = True,
primary_key = True,
max_length = CRYPT_KEY_LEN_MAX+1+len(KEYPREFIX)+len(KEYSUFFIX),
unique = True,
blank = True)
This fixed the problem for me. Otherwise it works very smoothly and as expected!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.