Skip to content


Subversion checkout URL

You can clone with
Download ZIP


need model howto #8

mixmastamyk opened this Issue · 13 comments

3 participants


Have installed the app and it is almost working correctly, however its not clear from the docs or sample app what fields I should add to my user profiles?

From the form blurb I see:
user.stripe_id, profile.last_4_digits, profile.stripe_customer_id

Would appreciate some guidance on where these come from and how to define these.


Hey Mixmastamyk,

You shouldn't have to add any fields directly - just use the models as mixins to your profile, and you should be set. (ie. have MyProfileModel inherit StripeCustomer, MyPlanModel inherit StripePlan, etc.

Agree that we need better docs on this though, leaving this issue open until we have them.



Thanks, interesting design. I chose this app over django-stripe because it had some documentation.

Do I need to make a plan model? Hmmm.



Yeah, the mixin/subclass is pretty standard, and a nice pattern. You don't need to have a plan model, unless you want to do something with it within your app. In short, I'd figure out your data needs, and see what you need to store locally. Then, use the mixins to get the functionality you need.

Also, since it is open source, more/better doc pull requests are always appreciated. :)


Sorry, I know this isn't a chat client, but what is user.stripe_id ? It seems to come out of nowhere in the view. Later on customer(Profile).stripe_customer_id is set. Are they the same thing? Is there a typo?

I made a profile model so I wouldn't have to hack on the Django user so would rather not save things to user.


Absolutely put it on your profile. And stripe_customer_id is the field you want. I think it's a typo. I'll double-check, then fix it up real quick.


Thanks again, and for the quick response.


Yup, and fixed up now. Will look at your pull request a bit later this week when I do my code reviews for all the projects I'm maintaining.


Thanks. I added StripeCustomer mixin to my profile (had to go before Model).

However, it doesn't have the last_4_digits field. I don't see the field in or I guess this code hasn't actually been run? hehe. Also the form code assumes the customer was already created, but I've got it handled now.


Parts of the code have been run, but as a part of a bigger app. The rest is (and was intended to be) pseudocode. I need to make the docs better. The last_4_digits field is supposed to show an example of storing some data locally, to cache it for speedier access, etc.

It's the developer's decision on whether or not they need last_4, or any of the stripe data to be cached locally. Creating the customer's up to you, unless you have ZEBRA_AUTO_CREATE_STRIPE_CUSTOMERS set to True. Then, one would be auto-created on the first stripe_customer access.

Clearly, the docs could use some cleanup. :)


Ok, thanks. I missed that the id was in the StripeCustomer and not the StripeMixin. I found the auto-create code.

Hopefully last question, :) ... what is the difference between saving the customer_id in the user profile vs saving it in the Customer table that the app created on install?


No real difference - it's all in where you want to keep it. We designed zebra to be really, really flexible, since it often has to fit into existing billing models. (I moved mine over from chargify to stripe.) There's not really a "right" way to do it, just a lot of options of which hopefully one fits you well. :)


curious, why wouldn't StripeCustomer use a foreign key relationship to User?


@tomstrummer - because that's not always what someone's schema needs.

In my case, my stripe accounts are tied to organizations, which have several users. For other people, it's profiles (one-to-one with user), for others, it's none of the above, and has nothing to do with users. Leaving it as a mixin is a more flexible way to solve the problem.

Also, for cases where what you want is a FK to User, the recommended way is to subclass your Profile class with StripeCustomer, to keep django happy, and keep things DRY.

@skoczen skoczen closed this
@skoczen skoczen reopened this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.