Opened 6 years ago

Closed 6 years ago

#12316 closed (invalid)

GenericForeignKey produces an error when submitting from a form

Reported by: djansoft Owned by: nobody
Component: Uncategorized Version: 1.1-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I apologize for not making a better report, but I cannot afford the time right now to write the minimum amount of code to reproduce this.

Snippet from my models.py:

class Subscription(models.Model):
    user = models.OneToOneField(User, primary_key=True)
    promotion = models.ForeignKey(Promotion)
    start_date = models.DateTimeField(auto_now_add=True)
    # Foreign key to AuthorizeNetSubscription u other model
    payment_gateway_subscription = generic.GenericForeignKey()
    is_active = models.BooleanField(default=True)


class AuthorizeNetSubscription(models.Model):
    subscription_id = models.CharField('subscriptionId in the ARB API call return', 
            max_length=16, primary_key=True)

Snippet from my forms.py:

        authorize_net_subscription = AuthorizeNetSubscription(
                subscription_id=result_dict.subscription_id.text_)
        user = User.objects.create_user(
            username = form_list[1].cleaned_data['display_name'],
            email=email,
            password=password,
        )
        subscription = Subscription(
            user=user,
            promotion=promotion,
            start_date=start_date,
            payment_gateway_subscription=authorize_net_subscription
        )

It fails in the line that creates the Subscription instance with a TypeError exception "'object_id' is an invalid keyword argument for this function" coming from line 320 in django/db/models/base.py

Change History (1)

comment:1 Changed 6 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

You appear to have skipped steps 1 and 2 listed here: http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1

Step 3 alone is not all you need in your model to have a working GenericForeignKey, you need to include 1 and 2 as well.

Note: See TracTickets for help on using tickets.
Back to Top