保存时验证错误

时间:2013-07-02 12:34:15

标签: python django save validationerror

OUr订阅者无法取消订阅其会员资格。我似乎无法从追溯错误中找到问题。(ValidationError:django.utils.functional。代理对象位于0x96d1f8c 希望你能提供帮助。

这些是过程中使用的功能。

def unsubscribe_user(request, user, subscription, silent=False):
    unsubscribe_user_cron(user, subscription, silent, request)

def unsubscribe_user_cron(user, subscription, silent=False, request=None):
    subscription.current = False
    subscription.save()

这是如何创建订阅对象的。

def subscribe_user(
    request, user, subscription_plan, gateway, reference_code, password=None):

    new_sub = Subscription.objects.create(user=user,
                                    plan=subscription_plan,
                                    start_date=start_date,
                                    end_date=end_date,
                                    first_payment_date=first_payment_date,
                                    gateway=gateway,
                                    reference_code=reference_code,
                                    current=True)

这是订阅模式。

class Subscription(models.Model):
    user = models.ForeignKey(User)
    plan = models.ForeignKey(SubscriptionPlan)
    start_date = models.DateTimeField(_("Start Date"))
    end_date = models.DateTimeField(_("End Date"), blank=True, null=True)    
    first_payment_date = models.DateTimeField(_("First Payment Date"))
    next_payment_date = models.DateTimeField(_("Next Payment Date"))
    status = models.CharField(_("STATUS"), blank=True, max_length=32)
    GATEWAY_CHOICES = (
        ('paypal', _('PayPal')),
        ('payflowpro', _('Payflow Pro')),
        ('cheque', _('Cheque (No gateway)')),
    )
    gateway = models.CharField(_("Ecommerce Gateway"), choices=GATEWAY_CHOICES, blank=True, max_length=20)
    reference_code = models.CharField(_("Reference Code"), blank=True, max_length=250,
        help_text=_("A reference code for the subscription. May not be necessary for all gateways"))

    # save the credit card expiry locally so we can prompt the user
    card_expiry_month = models.PositiveIntegerField(_("Card Expiry Month"), null=True, blank=True)
    card_expiry_year = models.PositiveIntegerField(_("Card Expiry Year"), null=True, blank=True)

    current = models.BooleanField(_("Is Current"), default=True)

    advance_renewal = models.BooleanField(_("Has Renewed in Advance"), default=False)

    class Meta:
        ordering = ('-start_date',)

    def save(self, *args, **kwargs):
        super(Subscription, self).save(*args, **kwargs)

调用取消订阅功能的脚本的一部分

elif data['txn_type'] == "subscr_cancel":
            # User has cancelled a specific subscription
            subscription_id = data['subscr_id']            
            try:
                subscription = Subscription.objects.get(user=user,plan=subscription_plan,reference_code=subscription_id)     
                unsubscribe_user(request, user, subscription)
            except Subscription.DoesNotExist:

这是收到的追溯错误

Traceback (most recent call last):
  File "C:\Users\noel\Dropbox\developer\sites\rkb1\oa\ecommerce\views.py", line 97, in paypal_ipn
  File "/var/www/ninjapyjamas/oa/subscriptions/helpers.py", line 192, in unsubscribe_user
    unsubscribe_user_cron(user, subscription, silent, request)
  File "/var/www/ninjapyjamas/oa/subscriptions/helpers.py", line 206, in unsubscribe_user_cron
    subscription.save()
  File "/var/www/ninjapyjamas/oa/subscriptions/models.py", line 152, in save
    super(Subscription, self).save(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 431, in save
    self.save_base(force_insert=force_insert, force_update=force_update)
  File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 495, in save_base
    rows = manager.filter(pk=pk_val)._update(values)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 446, in _update
    query.add_update_fields(values)
  File "/usr/lib/python2.5/site-packages/django/db/models/sql/subqueries.py", line 249, in      add_update_fields
    val = field.get_db_prep_save(val)
  File "/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py", line 202, in  get_db_prep_save
    return self.get_db_prep_value(value)
  File "/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py", line 446, in get_db_prep_value
    return self.to_python(value)
  File "/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py", line 442, in to_python
    ugettext_lazy("This field cannot be null."))
ValidationError: django.utils.functional.__proxy__ object at 0x9869f2c

0 个答案:

没有答案