Django 1.5 AbstractBaseUser with char primary key not JSON serializable -



Django 1.5 AbstractBaseUser with char primary key not JSON serializable -

i having next custom user model trying utilize 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 = ['email','website'] class meta: verbose_name = _('merchant') verbose_name_plural = _('merchants') def __unicode__(self): homecoming self.company_name

the model works , database expected, problem when seek dumpdata create fixtures tests.

python manage.py dumpdata --natural --exclude=contenttypes --exclude=auth.permission --indent=4 > fixtures/initial_data.json

then error:

commanderror: unable serialize database: <merchant: test shop> not json serializable

do have ideas reason this. charfield primary key or abstractbaseuser model?

thanks

after time spend found problem. not in merchant model in product has foreign key merchant:

class product(models.model): name = models.charfield(max_length=200) #merchant = models.foreignkey(merchant, to_field='api_key') merchant = models.foreignkey(merchant) url = models.urlfield(max_length = 2000) description = models.textfield(blank=true) client_product_id = models.charfield(max_length='100') objects = productmanager() class meta: verbose_name = 'product' verbose_name_plural = 'products' unique_together = ('merchant', 'client_product_id',) def __unicode__(self): homecoming self.name def natural_key(self): homecoming (self.merchant, self.client_product_id)

the natural_key method in model returned self.merchant instead of self.merchant_id trying serialize whole merchant object create natural key. after switching natural_key method next 1 problem fixed:

def natural_key(self): homecoming (self.merchant_id, self.client_product_id)

django json django-1.5

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -