On Fri, 2009-05-08 at 16:31 -0700, paul wisehart wrote: > I didn't realize that id was a python builtin function. > > I have a large pre-existing database that I wrote a bunch of models > for. > > I used 'id' as the primary key field for all of them. > > """ > class SalesQuoteItemDetail(models.Model): > id = models.AutoField(primary_key=True, db_column='ID') > ... > """ > > Could that hurt anything to name a field the same as a built-in > function?
It's fine, because the namespaces are different (namespaces are a *good* thing). Your "id" name is in the SalesQuoteItemDetail namespace -- you'll always be referring to it as an attribute of an object of that type. Python's id() function is in the global (well, builtins) namespace. The only thing to watch out for with model field names is that you don't name them after any existing method (e.g. a field name called "save" would be a bad idea). Field names -- which are Python model attributes -- are in the same namespace as methods on the same models -- since methods are attributes as well, with type "instancemethod". Fortunately, all model methods have fairly unusual names for that reason and the odds of you colliding are practically zero. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---