Hi Daryl,I agree and disagree with you, it depends on place and context of 
using "pk" alias :)I am not sure if it is good in filter and as object 
attribute. For our internal use we could use "_pk" or other name.You motivated 
me to check one thing.class Car(models.Model):    pk = 
models.IntegerField(primary_key=True)(fields.E003) 'pk' is a reserved word that 
cannot be used as a field name.That is because we implicity create "pk" field 
(what is against The Zen of Python - Explicit is better than implicit ;)) and 
it is used in public api and internally.Basic idea, introduced at the beginning 
of Django (16 years ago), assumes that every table has primary key. What is not 
true in real life.If we released this, developers could create (if they like 
generic):class ModelA(models.Model):    pk = 
models.IntegerField(primary_key=True, db_column="id")class 
ModelB(models.Model):    pk = models.CharField(max_length=10, 
primary_key=True, db_column="name")class 
ModelC(models.Model):    pk = 
models.DateTimeField(primary_key=True, db_column="created_on")and can filter by 
"pk" or use as object attribute as they do now.This is more flexible from our 
point of view. This also allow create models without prlmary key. Models could 
have method or property "has_primary_key" that will return True or Falseor 
"get_primary_key" which could return None if PK doesn't exist otherwise 
dictionary {<field name>: <field value>}. I think that something 
like this is used internally. Of course it would involve changes in other parts 
of Django like generic views, admin panel etc. But step by step we could 
improve it.Until we allow users use "pk" alias, created implicity, in filters 
(public orm api) and as object attribute we have hands tied.

-- 
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-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/muwmdzznxleaadxvzhqk%40dccs.

Reply via email to