On Wed, Apr 9, 2008 at 4:01 AM, firtzel <[EMAIL PROTECTED]> wrote: > > Hi, > > I created a model (Catalog), which is linked to its items via a m2m > relationship. > I added a raw_id_admin=True to the items field (good when I have a > long list of items). > Also, for convience reasons I wanted a different pk for my items, so I > added primary_key=True to one of the fields (in the simplified example > below, its name). > > This does not seems to work properly when trying to link more than one > item to the catalog. > In the models.py below, I added two fields - one is good_items, which > contains a 'regular' id field, and works fine, and the other - > bad_items, which creates the above problem. > Also, I added validator_list=[isOnlyDigits], since non-integer id's > caused another problem while adding these items to the catalog. > > I checked it with version 0.96.1 and current version from trunk (7403) > - fails on both. > > Any suggestions where to go from here? (beside removing the > primary_key=True, and using a regular id field, of course) > > models.py: > > from django.db import models > from django.core.validators import isOnlyDigits > > class BadItem(models.Model): > name = > > models.CharField(maxlength=50,primary_key=True,validator_list=[isOnlyDigits]) > > def __str__(self): > return self.name > > class Admin: > list_display = ('name',) > > class GoodItem(models.Model): > name = > models.CharField(maxlength=50,blank=False,null=False,unique=True) > > def __str__(self): > return self.name > > class Admin: > list_display = ('id','name') > > class Catalog(models.Model): > name = models.CharField(maxlength=50,blank=False,null=False) > good_items = models.ManyToManyField(GoodItem,raw_id_admin=True) > bad_items = models.ManyToManyField(BadItem,raw_id_admin=True) > > class Admin: > list_display = ('id','name',) >
A few details on what "does not seems to work properly" looks like might help people help you. As it is I don't have any real clear idea of what is causing the problem without recreating it myself, which I don't have time for right now. One thing I find odd is that you decided to limit your CharField to only digits -- if you are going to do that, why not just convert it to a numeric field instead? That would make it more like the default primary key field, so might fix the problem. (Though I'm also not sure how wise it is to be trying to use the name field as a primary key in the first place.) 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---