Django - How to allow access to read one model object from another django site hosted on another server - django

Like I said in the title, I need to know how can I allow access to the objects from one model of a Django app from another Django app.
For example, I have a Django App on one VPS, and the other on another VPS. In the first one, I publish daily news about science. I like to put a div in the other Django app landing page that shows the news that I publish in the first app.
I know that I didn't put any code, but this is because I don't know how to start. I need the first push to help me figure how to make this and then I'm pretty sure that I can come back to make specific questions.

Related

How to manage multiple websites with 1 django project

Let's say I have 1 Django project where I want host multiple websites on with different domains. I managed to set it up but progressing further is where I get confused.
We'll call them store1.com, store2.com
I can route to both sites through a custom middleware that checks the url where the request comes from and that is working fine.
Both stores have it's own apps like cart, category, product, account and so forth.
What would be the best practice to structure this?
Do I put everything from a store inside 1 app or is it better to have all these models and views in a separate app and keep checking the request so that the app knows which URL to serve?
IMHO the best way is to create an app for all the different functionalities and then use Django Sites framework to manage multiple sites.
You can read more on the Django documentation

React + Django app refreshes for every deletion in Django admin panel

I'm not really sure what to share (i.e. which part of my application code) as I'm still a beginner with React so please bear with me.
I have a React application running on top of a Django application. Basically, there are Django Admin Panel URLS, REST API URLS in Django, and one path to catch all paths that don't belong to the first two groups.
I have a page (or a React Container) that calls Django's REST API to query all entries in the users DB Table. This part is okay but what I've noticed is, everytime I manually delete a row in the Django Admin Panel, the whole page refreshes. What are possible reasons for this?
By the way, I'm using Redux as well to manage the whole application state.

Ember application with an admin site

I'm creating a basic Ember application. I am trying to set up a backend that stores posts. I would like to have a system where I can go to some admin site that has a form that has all the fields for a post that allows me to add, update, and delete posts. For example, if I have a Post model with attributes like Title, Contents, Date_created, and Image, I would like to have these fields in a form in some kind of admin site.
One example from a past tutorial I have done is the Django admin site. Is it possible to set up a Django backend for my Ember app? The Django admin is here: (scroll to bottom)
https://docs.djangoproject.com/en/1.10/intro/tutorial02/
I know that asking how to set up a backend for my Ember application is a very general question, but I am confused as to where to start. I have already created a Post model with various attributes. I can create an Ember route that is a form to add a post, but then there comes authentication for that which I'm not really sure how to deal with either. That's why I came to Django because I remember they had a very nice admin site.
If it is not feasible to use Django to accomplish this, what are some other routes I can take to be able to get to some admin page where I can manipulate records and add new data to my website?
This is a pretty big question, but I feel your pain. Most tutorials are all, "so... just build out a rails app... or use all this long lost stubbing stuff... or here's a super outdated node server on github to use."
I would suggest breaking it down into pieces. Ember is really great, but–Yes–you need a backend. You could make a backend with Django(python), Rails(ruby), WordPress(PHP) + ember-wordpress, express or hapi(node), phoenix(elixir)- or really anything that will generate an API. You could also build an admin with Ember and then use that to send data to a service like parse or firebase. Those could get you an MVP while you learn more about how to build out a traditional back-end.
Django + http://www.django-rest-framework.org has a pretty great admin setup that builds out the admin and fields from your API specifications. I can see why people like it.
I would also mention, that ember-cli-mirage is great when you aren't sure what backend you'll have, but you need to have a mock-server to build off of.
If you can, choose something that will spit out an API with jsonAPI.
I would split this into 2 parts.
build out an Ember app with Mirage or some other temporary data.
build a back-end somehow.
Then you can connect them ~ without being stuck beforehand.
Good luck!
So pretty much a blog site where only person can create/delete/edit posts? If so then all you have to do is create a user with a predefined username and password in your Django app. You login through your Ember app. For this protected view you will need to use ember-simple-auth, which is the simplest way to implement something like this. Google ember-simple-auth and run its dummy app to see what they are doing.

Wordpress database integration/sync with Django

My company will be rolling out a new website to accompany our product launch and would like to switch over to Wordpress as our content management system. We will be utilizing a Wordpress theme that will allow users to create their own virtual events without having to log into the Wordpress dashboard (back-end). This event information will be displayed on the website for other users to view and register - this is all built into the theme we have purchased.
These virtual events will be held on our software platform, which is built on Django. We would like to utilize Wordpress to manage the login and event creation process, but would also like to have event information displayed on the Wordpress site AND imported to the Django database as well.
For example: Users will need to submit three items on the front-end Wordpress site to create an event: Title, Host Name, and Start Time. When that information is submitted can it be automatically duplicated to the Django database in addition to it being sent to the WP database?
I have already done some research on this matter, but what I have found thus far might not work for our needs. I found this presentation by Collin Anderson - it is similar to what we want to achieve, but I believe the application is a little different: http://www.confreaks.com/videos/4493-DjangoCon2014-integrating-django-and-wordpress-can-be-simple.
I have a lot of experience with Wordpress, but very limited experience with Django. This question is more for research purposes than a "how-to". We want to know if we can continue to plan on heading toward the Wordpress direction or if we should seek alternative methods for our site. I appreciate you taking moment to answer my question.
I'm working on something similar at the moment and found a good starting point was this:
http://agiliq.com/blog/2010/01/wordpress-and-django-best-buddies/
That way, as dan-klasson suggests, you can use the same database for both the wp side and the django side.
In short, first things first take a back up of the wp database in case anything goes wrong.
Create a new django project and set your settings.py to use the wp database.
In this new django project you can use ./manage.py inspectdb > models.py to autogenerate a models.py file of the wp database. Be careful here as there are differences between wp and django conventions. You will need to manually alter some of the auto generated models.py. Django supplies db_table and db_column arguments to allow you to rename tables and columns for the django part if you'd like to.
You can then create a new django app in your django project and place the models.py you've created in there. This new app will be using the same data as your wordpress site. I'm not sure exactly what you want to do but I would be very, very careful about having wordpress and django access the same data simultaneously. You may want to set the django side as read only.
You can then add other apps to extend the django side of things as you wish.
I should point out that I haven't completed my work on this yet but so far so good. I'll update as I find sticking points etc.

How to setup groups (sub-sites) in Django

I'm new to Django and I come from Drupal family. There we have Organic Groups with which we can create groups of content and subsites; how do I do something like that with Django?
Say I'm making this site for my company using Django and every department in my company needs a private section on the site. For example, the design people have their own part of the website into which the back-end developers can not come in. And the back-end developers will have the same thing too.
I want to build the site in such a way that I just login into Django admin and add a new category or subsite or group (whatever the Django term is) with the same settings from other groups or with similar settings.
It depends on what you mean by "private section". You should probably try looking at it from a different angle:
Django splits a site's functionality by means of "apps". Each app does its specific thing, and gets a set of tables in the database. Apps can access each others' tables. For example, it's common for other apps to access the Auth app's user, group, and permissions tables. Is this what you mean by "sub sites"?
As for access control, users can be assigned to groups and they can have various administrative permissions assigned to them. Add, change, and delete permissions are automatically generated for each model (i.e. database table). You can also add your own permissions.
I don't think you'll be able to separate the designers from the back-end developers at the Django level. You'll need to do something else, such as maintain separate source repositories for each and merge them to create the usable site (each group would have read-only access to the other). It really depends on your teams' discipline, because these elements can get intertwined.
Django recommends that static files be served by something else, say directly from your web server, or from another machine with a simple HTTP server (no CGI/WSGI/whatever). This is because Django can only slow down static files compared to direct service. However, for testing, ther is a static page server you can enable.
Given all that, static files usually amount to CSS, images, media, and JavaScript. Of these, the back-end people might want to mess with the JS, but that's it, so this could be in the designers' repo.
The Django tree itself has the code for the site and the apps. It's almost all back end stuff. The exception is the HTML template files, located in the "templates" directory in each app. These are the files that are filled in with the context data supplied by the back-end view code. I have no idea if this is front or back end for you guys; it could be mostly back end if there's a lot of CSS discipline, but I think that's unlikely.
There are a lot of things that you can do in Django that make life easier for one side or the other. For example, template tags allow custom Python code to generate HTML to insert into the page. I use these to generate tab bars and panes, for example.
I really can't help much more without getting a better picture of what your needs are. The question is still vague. You're probably best off taking a day or two going through the tutorial, seeing what the Django perspective is, and then working out how (or if!) it fits into your needs.