Sorry for the dumb question (and I feel that it is dumb). I only comprehend Django.
When I try to save the created promo , I get this error:
The database backend doesn’t accept 0 as a value for AutoField.
My model:
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models from django.utils import timezone from django.utils.translation import ugettext_lazy as _, pgettext_lazy from django.conf import settings from django.contrib.auth.signals import user_logged_in from django.contrib.sites.models import Site import string import random from catalog.models import Category from mptt.forms import TreeNodeChoiceField from mptt.models import TreeOneToOneField def id_generator(size=16, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) class Promo(models.Model): promo = models.CharField(_('promo'), max_length=50, blank=False, default=id_generator) discount = models.DecimalField(_('Discount %'), max_digits=14, decimal_places=2, default=0, blank=True) discount_money = models.DecimalField(_('Discount (rub)'), max_digits=14, decimal_places=2, default=0, blank=True) order_id = models.CharField(_('order number'), max_length=50, blank=True, default=0) first_name = models.CharField(_('first name'), max_length=30, blank=True) last_name = models.CharField(_('last name'), max_length=30, blank=True) part_number = models.CharField(_('part number'), max_length=255, blank=True) category = TreeOneToOneField(Category, verbose_name=_('category'), blank=True, default=0) date_end = models.DateTimeField(_('Date end'), default=timezone.now) class Meta: verbose_name = _('promo') verbose_name_plural = _('promo') def __unicode__(self): return self.promo @classmethod def create(cls, discount_money): promo = cls(discount_money=discount_money) promo.save() return promo What is the reason for this error?
def subscribe(self, email): self.model_class.objects.get_or_create( email=email, ) self.create_promo() @staticmethod def create_promo(): promo = Promo.create(config.SUBSCRIPTION_DISCOUNT) print promo
defaultfrom there? All the same there isblank=true. - Viktor