On Jun 4, 5:42 pm, "Cliff Liang Xuan" <[EMAIL PROTECTED]> wrote: > Basically I want to use a random 7 digit string as the primary key of table > Foo, because this id is system generated I don't want to show it in the > admin interface. How to achieve this, please?
You should only have trusted users in the admin anyway, so I don't see what the problem is with incrementing IDs, but auto generation is easy. You just need to create your own save() method that sets the ID and then calls the existing save() method of the model class. For example: def save(self): self.id = self.getRandom(); super(Foo, self).save() That should do the trick. Though depending on your use, you'll want to first check if self.id exists so it won't give a new one on each save(). I do the same thing for one of my models to use a UUID. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---