On Sun, Feb 8, 2009 at 7:51 PM, Patricio Palma <patriciopa...@ic.uach.cl>wrote:
> [snip] > ----------------------------------------------------------- > models.py > from django.contrib.auth.models import User > class MyUser(User): > chilean_rut = CLRutField(_('RUT'),primary_key=True) > some_field = models.CharField(max_length=50) > ------------------------------------------------------------ > admin.py > class MyUserAdmin(admin.ModelAdmin): > list_display = ('chilean_rut', 'email','some_field') > admin.site.register(MyUser,MyUserAdmin) > > ------------------------------------------------------------- > > And my list_display is EMPTY ( on the > http://127.0.0.1:8000/admin/myapp/myuser/) > The problem here seems to be caused by setting primary_key=True on one of the fields in the model that inherits from another. You can see it using just these simple models: class BaseM(models.Model): base_name = models.CharField(max_length=100) def __unicode__(self): return self.base_name class DerivedM(BaseM): customPK = models.IntegerField(primary_key=True) derived_name = models.CharField(max_length=100) def __unicode__(self): return "PK = %d, base_name = %s, derived_name = %s" % \ (self.customPK, self.base_name, self.derived_name) and manage.py shell (output reformatted for readability): Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from ttt.models import DerivedM >>> from django.db import connection >>> DerivedM.objects.create(customPK=44, base_name="b1", derived_name="d1") <DerivedM: PK = 44, base_name = b1, derived_name = d1> >>> DerivedM.objects.all() [] >>> connection.queries[-1] {'time': '0.006', 'sql': u'SELECT `ttt_basem`.`id`, `ttt_basem`.`base_name`, `ttt_derivedm`.`basem_ptr_id`, `ttt_derivedm`.`customPK`, `ttt_derivedm`.`derived_name` FROM `ttt_derivedm` INNER JOIN `ttt_basem` ON (`ttt_derivedm`.`customPK` = `ttt_basem`.`id`) LIMIT 21'} >>> The ORM is joining the two tables and attempting to match the manually-specified custom PK from the child table to the auto-generated id in the parent table, which results in finding nothing. I do not know if specifying primary_key=True on a field in a child table is just not allowed (in which case it should probably be flagged as an error during validation) or if the ORM should be handling this properly. I do not see any ticket open that describes this case; you might want to open one since it seems something ought to be changed here to either report an invalid model definition or handle this case properly. Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---