Changing the primary key of Django models

閲覧: 80 回
最初の未読メッセージにスキップ

Uri Even-Chen

未読、
2016/02/05 15:52:122016/02/05
To: django-d...@googlegroups.com、speedy-mai...@googlegroups.com
To django-d...@googlegroups.com,

I'm a Django user and I'm working on converting Speedy Net from PHP to Django. I would like to know if it's possible in Django to change the primary key of Django models, such as User? I don't like the auto-increment default primary key, it doesn't make sense, and I want to use the primary key of users and pages also in urls. And therefore I decided that the id of users and pages, causes, groups and events on Speedy Net will be 15 randomly generated digits. Users who already created accounts and pages on Speedy Net (with PHP) already have a 15-digits id, and I want to preserve this number when converting Speedy Net to Django. Is it possible? I don't want the id/primary key to be short (such as zuck's id on Facebook - https://www.facebook.com/messages/4) but 15-digits long.

Thanks,
Uri.

Uri Even-Chen  
photo Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
   


---------- Forwarded message ----------
From: Uri Even-Chen <u...@speedy.net>
Date: Thu, Feb 4, 2016 at 6:20 PM
Subject: ID for users of Speedy Net
To: django...@googlegroups.com
Cc: speedy-mai...@googlegroups.com


To django...@googlegroups.com,

I'm working on the next version of Speedy Net, which will be based on Django 1.9.2 and Python 3.5 / 3.4. You can see the specification of Speedy Net on https://github.com/urievenchen/speedy-net/tree/master/speedy_net/specifications (the file is System Requirements Specification - Speedy Net.txt). The old code is in PHP and can be found on https://www.assembla.com/spaces/speedynet/subversion/source (all the Speedy Net projects are free software and open source). According to my specification, each user will have a unique ID of 15 digits (a number between 100,000,000,000,000 and 999,999,999,999,999, randomly generated), which will be unique over the system (of users, pages, groups, causes and events). And each user will have a username, and pages, groups and causes may also have an optional username (it's called "username" also on Facebook).

So my question is, can I make this random ID the primary key of the User model? I don't want users to have 2 ids - one for Django and one of Speedy Net, it doesn't make sense. I want the id to be the same and unique. I also want to have an Id model to prevent a page and a user (for example) to have the same ID. And a Username model to prevent them from having the same username. Is it possible to do it with Django 1.9.2?

By the way, if you want to help me develop Speedy Net, Speedy Composer, Speedy Match or Speedy Mail, please let me know. If you want you can also join Speedy Net and grab yourself a username at Speedy Net. I'm also sending a copy of this message to speedy-mai...@googlegroups.com, the list of developers of the Speedy Net projects.

I have another, off-topic question. Anyone knows how I can create a company in Switzerland, and how much does it cost? Any links to lawyers who can do it for me? I decided to host Speedy Net in Switzerland, because of the privacy laws there, and I prefer a Swiss company for the same reason (Israel is much less advanced in privacy than Europe and Switzerland). I'm a resident and citizen of Israel, with an option to become a Spanish citizen too. And I don't want to host private information of people in Israel.

Thanks,

Dheerendra Rathor

未読、
2016/02/05 18:10:042016/02/05
To: django-d...@googlegroups.com、speedy-mai...@googlegroups.com
Yes you can keep custom primary key. Pass `primary_key=True` in your model and Django won't create a primary key for that model. 


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMQ2MsGMip-WreMzjrpZFxJUB3edJz9RQoiMLoo5tEwjU-7pfw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Tim Graham

未読、
2016/02/05 18:36:092016/02/05
To: Django developers (Contributions to Django itself)、speedy-mai...@googlegroups.com
By the way, the django-developers mailing list is about the development of Django itself. Please keep usage questions limited to django-users. Thanks!
全員に返信
投稿者に返信
転送
新着メール 0 件