Discussion:
Best way to structure this Django project
(too old to reply)
Simon Connah
2018-12-02 23:31:14 UTC
Permalink
Hi,

I have a bit of a problem with structuring a Django project. I have a
UserProfile app which stores extra information about users using a
OneToOneField to the Django auth user model.

I have a products app which has two models relating to two types of
products and finally I have a payments app which contains all the code
needed to integrate with the Stripe payment processor.

My problem is fairly simple. When someone buys a product I obviously
want to take them to a payment page but if I carry on with my current
structure that would require redirecting to a view in the payments app
as it will contain code to work with the Stripe API but it would also
require access to the product model(s) which would hard code a
dependency between the payments app and the products app.

Is there anyway I can rearrange my project so I can avoid this hard
coded dependency?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/12030aa1-69ad-dc7f-c3be-72e8e2f9b50e%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Matthew Pava
2018-12-03 16:20:20 UTC
Permalink
I don't think there's a way around it, but that's okay. I have dependencies between several apps in my project, and the apps help organize the project.
If you don't want to necessarily hard-code the app model, you could pass in the model as an argument and use apps.get_model(app_name, model_name) inside the function.

-----Original Message-----
From: django-***@googlegroups.com [mailto:django-***@googlegroups.com] On Behalf Of Simon Connah
Sent: Sunday, December 2, 2018 5:31 PM
To: django-***@googlegroups.com
Subject: Best way to structure this Django project

Hi,

I have a bit of a problem with structuring a Django project. I have a
UserProfile app which stores extra information about users using a
OneToOneField to the Django auth user model.

I have a products app which has two models relating to two types of
products and finally I have a payments app which contains all the code
needed to integrate with the Stripe payment processor.

My problem is fairly simple. When someone buys a product I obviously
want to take them to a payment page but if I carry on with my current
structure that would require redirecting to a view in the payments app
as it will contain code to work with the Stripe API but it would also
require access to the product model(s) which would hard code a
dependency between the payments app and the products app.

Is there anyway I can rearrange my project so I can avoid this hard
coded dependency?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/12030aa1-69ad-dc7f-c3be-72e8e2f9b50e%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1b12d5105a8c457e8fc7b1f45312141c%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.
Pankaj Kumar
2018-12-03 18:06:06 UTC
Permalink
Thats a valid workflow in my opinion. Many Django works take that approach.

But alternatively, if you want you can pass the product info as parameters
in the Payment app while redirecting and can have a model in the Payment
app to capture and integrate product and payment parameters together. That
way you can avoid importing the Product model but retaining the product
informations along with payment informations.
Post by Matthew Pava
I don't think there's a way around it, but that's okay. I have
dependencies between several apps in my project, and the apps help organize
the project.
If you don't want to necessarily hard-code the app model, you could pass
in the model as an argument and use apps.get_model(app_name, model_name)
inside the function.
-----Original Message-----
On Behalf Of Simon Connah
Sent: Sunday, December 2, 2018 5:31 PM
Subject: Best way to structure this Django project
Hi,
I have a bit of a problem with structuring a Django project. I have a
UserProfile app which stores extra information about users using a
OneToOneField to the Django auth user model.
I have a products app which has two models relating to two types of
products and finally I have a payments app which contains all the code
needed to integrate with the Stripe payment processor.
My problem is fairly simple. When someone buys a product I obviously
want to take them to a payment page but if I carry on with my current
structure that would require redirecting to a view in the payments app
as it will contain code to work with the Stripe API but it would also
require access to the product model(s) which would hard code a
dependency between the payments app and the products app.
Is there anyway I can rearrange my project so I can avoid this hard
coded dependency?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/django-users/12030aa1-69ad-dc7f-c3be-72e8e2f9b50e%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/django-users/1b12d5105a8c457e8fc7b1f45312141c%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMAa5dNNmcJ%2Bz2HR%3DFuNJiFwP1T-dv5OTr3gJNx5-9v7NiwgWg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...