On Tue, Feb 12, 2013 at 9:03 PM, Kaloian <kaloian.min...@gmail.com> wrote:
> I am having the following custom user model trying to use the Django 1.5 > AbstractBaseUser: > > class Merchant(AbstractBaseUser): > email = models.EmailField() > company_name = models.CharField(max_length=256) > website = models.URLField() > description = models.TextField(blank=True) > api_key = models.CharField(blank=True, max_length=256, primary_key=True) > > USERNAME_FIELD = 'email' > REQUIRED_FIELDS = ['company_name','website'] > > > class Meta: > verbose_name = _('Merchant') > verbose_name_plural = _('Merchants') > > def __unicode__(self): > return self.company_name > > > The model works perfectly and database is as expected, but the problem is > when I try to dumpdata to create fixtures for my tests. > > python manage.py dumpdata --natural --exclude=contenttypes > --exclude=auth.permission --indent=4 > fixtures/initial_data.json > > > Then I get the error: > > CommandError: Unable to serialize database: <Merchant: Test Shop> is not JSON > serializable > > > > Do you have ideas what could be the reason for this. Could it be the > charfield primary key or something with the abstractbaseuser model? > > It's not immediately clear. The use of natural keys could also be a contributing factor here. What you've described isn't a problem I've seen previously, so you should open a ticket to track it. It would also be exceedingly helpful if you can try running a few tests to remove possible causes - e.g., * Does serialising *without* natural keys work? * Do you have any models with foreign keys to your custom user? (i.e., is the problem manifesting when serialising Merchant, or serialising foreign keys to Merchant?) * Do you still have problems if you use a 'normal' integer key? Essentially, any help you can provide in narrowing down the exact cause would be most helpful. Also, if you can run the tests with --traceback, we can get the full error logs. As a side note -- if you're using email as your username field, you should set it as unique=True -- USERNAME_FIELD needs to be unique or you'll experience problems later on. This is something that should probably be caught by validation - which is a bug deserving of it's own report. For performance reasons, you also probably want to set it db_index=True, since you're going to be searching on that field fairly often, so having an index on it makes sense. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.