Re: Custom Primary Key

2020-06-24 Thread Oleg Kishenkov
Yes, first you generate your custom key, second you specify it as the id of an object. id = 'A1B2C3D4E5' foo = Foo(id=id) foo.save() This code would create a record in the database. I also have to note that if you read this record to an object, changed it and saved it, the record wouldn't change

Re: Custom Primary Key

2020-06-24 Thread Clive Bruton
On 24 Jun 2020, at 06:24, Soumen Khatua wrote: Yes, at the time of add a new record in model, automatically I want to create a custom ID and insert it into model There is a post about this at Stack Overflow: https://stackoverflow.com/questions/52070462/django-generate-custom-id -- Clive

Re: Custom Primary Key

2020-06-23 Thread Soumen Khatua
Yes, at the time of add a new record in model, automatically I want to create a custom ID and insert it into model On Wed 24 Jun, 2020, 7:18 AM Clive Bruton, wrote: > > On 23 Jun 2020, at 23:32, Oleg Kishenkov wrote: > > > Hello Soumen, you should use a CharField with the primary_key=True > > at

Re: Custom Primary Key

2020-06-23 Thread Clive Bruton
On 23 Jun 2020, at 23:32, Oleg Kishenkov wrote: Hello Soumen, you should use a CharField with the primary_key=True attribute for your model. This way no no automatic primary key field is generated, your field will be implicitly unique and non- null though. Only one primary key is allowed i

Re: Custom Primary Key

2020-06-23 Thread Oleg Kishenkov
Hello Soumen, you should use a CharField with the primary_key=True attribute for your model. This way no no automatic primary key field is generated, your field will be implicitly unique and non-null though. Only one primary key is allowed in a model. class Foo(models.Model) id = models.Cha

Re: Custom Primary Key

2020-06-23 Thread Soumen Khatua
In the documentation they are specified, How to set Primary Key in Django model but In my case, I want to generate custom Primary Key?! On Wed, Jun 24, 2020 at 1:36 AM David Chorpash wrote: > Hi Soumen, > > Are you looking for this? > https://docs.djangoproject.com/en/3.0/ref/m

Re: Custom Primary Key

2020-06-23 Thread David Chorpash
Hi Soumen, Are you looking for this? https://docs.djangoproject.com/en/3.0/ref/models/fields/#primary-key You should be able to create a field in your model and set the primary_key to True On Tue, Jun 23, 2020 at 1:18 PM Soumen Khatua wrote: > Hi Folks, > > In Django is there any way to creat

Custom Primary Key

2020-06-23 Thread Soumen Khatua
Hi Folks, In Django is there any way to create custom Primark Key like: M01234GH, M056YUOIP, etc. Please help me guys. Thank you in advance Regards, Soumen Khatua -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group

how do we create a custom primary key in django

2018-10-30 Thread chaitak
id = models.CharField(primary_key=True,default='first') .how can i insert a custom auto generated primary with the organization name for example 'cha' and a number starting from 1000 so the final id would be cha1000 and next id would be cha1001 Thanks & Regars ch

django custom primary key problem.

2012-03-12 Thread Morris
Hi all, I have a custom primary key, but I can NOT get data from db. === **models.py** class BuildRecord(models.Model): sku_name = models.CharField(max_length=600, primary_key=True, db_column='SKU_name') download_link = models.CharField(max_length=1500,

Re: Custom primary key

2009-04-29 Thread Timboy
Thank you for your time and response Malcom, I appreciate it very much. On Apr 29, 3:42 pm, Malcolm Tredinnick wrote: > On Wed, 2009-04-29 at 15:37 -0700, Timboy wrote: > > I am trying to make a pk for an object that starts with the year > > followed by seven additional digits. YYXXX I want

Re: Custom primary key

2009-04-29 Thread Malcolm Tredinnick
On Wed, 2009-04-29 at 15:37 -0700, Timboy wrote: > I am trying to make a pk for an object that starts with the year > followed by seven additional digits. YYXXX I want the digits to > automatically increase like normal. > > I'm guessing I need to pass force_insert=True to my save if not > sel

Custom primary key

2009-04-29 Thread Timboy
I am trying to make a pk for an object that starts with the year followed by seven additional digits. YYXXX I want the digits to automatically increase like normal. I'm guessing I need to pass force_insert=True to my save if not self.pk. I'd appreciate some advice. TIA --~--~-~--~---

Re: Unicode broken if using a custom primary key?

2008-04-26 Thread Karen Tracey
f1 = models.CharField(maxlength=65, blank=True, null=True) > > 3. A test.json file: > > [{"pk": "203", "model": "testapp.Test", >"fields": >{"f1": "\u00c3"}}] > > 4. I dele

Unicode broken if using a custom primary key?

2008-04-26 Thread plamen.dragozov
"fields": {"f1": "\u00c3"}}] 4. I delete the db file and then from the command line I run: python manage.py syncdb testapp python manage.py loaddata fixtures/test.json If I leave the line with the custom primary key commented everything is fine and I get: Ins

Re: Custom primary key using Oracle 10g

2007-08-20 Thread Catriona
ot;C:\Python24\Lib\site-packages\django\db\backends\util.py", > > line 19, in e > > xecute > > return self.cursor.execute(sql, params) > > File "C:\Python24\Lib\site-packages\django\db\backends\oracle > > \base.py", line 1 > > 22, in execute > >

Re: Custom primary key using Oracle 10g

2007-08-15 Thread Ian
ckages\django\db\backends\util.py", > line 19, in e > xecute > return self.cursor.execute(sql, params) > File "C:\Python24\Lib\site-packages\django\db\backends\oracle > \base.py", line 1 > 22, in execute > return Database.Cursor.execute(self, query, para

Re: Custom primary key using Oracle 10g

2007-08-15 Thread Catriona
invalid identifier Sorry if I'm missing something really basic here but I am a bit confused. Thanks Catriona On Aug 15, 6:09 pm, Ian <[EMAIL PROTECTED]> wrote: > Catriona, > > Only AutoFields are auto-incrementing in Django. If you want to use a > custom primary key tha

Re: Custom primary key using Oracle 10g

2007-08-15 Thread Ian
Catriona, Only AutoFields are auto-incrementing in Django. If you want to use a custom primary key that isn't an AutoField, you will need to populate the primary key yourself (or else create a custom trigger for it), just as you would for any other column that is both NOT NULL and UNIQUE.

Re: Custom primary key using Oracle 10g

2007-08-14 Thread Catriona
uot; FOR EACH ROW WHEN (new.id IS NULL) BEGIN SELECT TEST_EMPLOYEE_SQ.nextval INTO :new.id FROM dual; END; / COMMIT; Am I missing something here? Thanks again Catriona On Aug 14, 6:24 pm, "Jon Atkinson" <[EMAIL PROTECTED]> wrote: > Catriona, > > I ha

Re: Custom primary key using Oracle 10g

2007-08-14 Thread Jon Atkinson
Catriona, I have very little Oracle experience, but also no reason to think that setting a custom primary key would be different from any other database backend. The documentation is here: http://www.djangoproject.com/documentation/models/custom_pk/ The primary key is set by using 'primar

Custom primary key using Oracle 10g

2007-08-13 Thread Catriona
Hello I am a beginning Django user and would appreciate help on the following issue. How do I specify a custom primary key in my model when using Oracle 10g I am using the lastest Django version from svn. Thanks for your help Catriona

Validating custom primary key values in raw_id_admin fields

2007-07-29 Thread Brendan Arnold
ref: http://groups.google.com/group/django-users/browse_thread/thread/9c9b05de723877a2/41c26d973af029d5?lnk=gst&q=raw_id_admin&rnum=10#41c26d973af029d5 hi there, there still seems to be this problem. i just checked out the svn about a week ago. it appears to be a problem with validation. the da

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-06 Thread Adrian Holovaty
On 10/6/05, Emanuele <[EMAIL PROTECTED]> wrote: > YESS! It works perfectly! > > Thank you very much, this solves an important problem in my > application. Excellent! Thank *you* for using Django. :-) Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-06 Thread Emanuele
YESS! It works perfectly! Thank you very much, this solves an important problem in my application. Emanuele

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-06 Thread Adrian Holovaty
On 10/6/05, Emanuele <[EMAIL PROTECTED]> wrote: > I'm sorry but after updating (revision 786) this simple example > still has the problem I reported: Hey Emanuele, Update your Django code to revision 790, and give it another shot! Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | ch

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-06 Thread Emanuele
I'm sorry but after updating (revision 786) this simple example still has the problem I reported: class Poll(meta.Model): question = meta.CharField(maxlength=200,primary_key=True) def __repr__(self): return self.question class META: admin = meta.Admin() pass

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-05 Thread Adrian Holovaty
On 10/3/05, Emanuele <[EMAIL PROTECTED]> wrote: > to avoid big drop-down lists in admin interface I'm using > "raw_id_admin=True" inside ForeignKey(), so I can enter > object IDs manually. But what happens if my related object has > a _non-numeric_ custom pri

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-04 Thread Jason Huggins
Adrian Holovaty wrote: > Oooh, that's a good idea. Django already displays the __repr__() of > the corresponding record on the *change* page, but it'd be nice to do > it automatically (via Ajax) right after the field is populated on the > add page (or changed on the change page). Yup... I notice

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-03 Thread Adrian Holovaty
On 10/3/05, Emanuele <[EMAIL PROTECTED]> wrote: > Wouldn't it be nice (useful?) if just after inserting the pk value (in > case of "raw_id_admin=True" I mean) we could see aside the __repr__() > of the corresponding record? Just as a double check. Using manual > insertion of pk values is a good al

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-03 Thread Emanuele
Thanks for the quick answer! Wouldn't it be nice (useful?) if just after inserting the pk value (in case of "raw_id_admin=True" I mean) we could see aside the __repr__() of the corresponding record? Just as a double check. Using manual insertion of pk values is a good alternative when dealing wit

Re: big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-03 Thread Adrian Holovaty
On 10/3/05, Emanuele <[EMAIL PROTECTED]> wrote: > to avoid big drop-down lists in admin interface I'm using > "raw_id_admin=True" inside ForeignKey(), so I can enter > object IDs manually. But what happens if my related object has > a _non-numeric_ custom primary

big drop-down lists, raw_id_admin and custom primary key: a bug?

2005-10-03 Thread Emanuele
Hi, to avoid big drop-down lists in admin interface I'm using "raw_id_admin=True" inside ForeignKey(), so I can enter object IDs manually. But what happens if my related object has a _non-numeric_ custom primary key? In my case I've a string as a custom primary key and I&