I have a custom product model
--------------------------------------------------------------------------------------------------------------------------
from django.db import models
from django.utils.translation import ugettext_lazy as _
from product.models import Product
class alkBrand(models.Model):
brnd = models.CharField(_("Brand"), max_length=30, blank=False,
help_text=_("alk help"))
def __unicode__(self):
return 'alkBrand %s' % (self.brnd)
class Meta:
verbose_name = _('alk-Brand')
verbose_name_plural = _('alk-Brands')
class LocalProduct(models.Model):
product = models.OneToOneField(Product, verbose_name=_('Base Product'))
code = models.CharField(verbose_name=_('Code'), max_length=32,
blank=True, null=True)
abrnd = models.ForeignKey(alkBrand)
def _get_subtype(self): return 'LocalProduct'
def __unicode__(self):
if self.code:
return u"%s [%s]" % (self.product.name, self.code)
else:
return u'%s' % self.product.name
class Admin: pass
class Meta:
verbose_name = _('aBrand')
verbose_name_plural = _('aBrands')
--------------------------------------------------------------------------------------------------------------------------
I can't find a way to add records to LocalProduct.
If i try to write
brand = alkBrand.objects.get(brnd='mybrand')
ppp=Product.objects.get(id=2)
ppp.LocalProduct.add(abrnd=brand,code='gino')
gives me
DoesNotExist: LocalProduct matching query does not exist.
If i add that record with backend admin interface i have no problem to
access that record in this way
ccc= ppp.LocalProduct.code
Thanks to all
--
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.