Django - creating an CRM like app makes me trouble - django

I would like to create an app which will help generate offers. Let's assume I have two apps in Django project:
offers which allows to: display offers list, creating the new ones
and updating an existing offer.
warehouse which allows to: display all goods added to warehouse, creating new ones, and updating existing goods.
During creating new offer I want to have a possibility to add some of the warehouse goods to the offer and set some additional parameters like: price, quantity and so on to print it on the offer. I want to achieve this using Bootstrap modal pop-up.
How should my models, and views files looks like to achieve this?
Should I use Many to Many relation ?
P.S. I am not sure if You even understand my doubts :D

Related

What is the best way to build Django model?

I want to make a website that gives a visualization of football game statistics.
Functionality: The user checks a list of games. Selects game to see details. Can select a particular player. If there is no game he/she is interested in, the user uploads a datafile of the game and adds it to the main list of games.
I have a script that cleans data and gives me DataFrame with columns:
['Shots', 'SCA', 'Touches', 'Pass', 'Carries', 'Press', 'Tackled', 'Interceptions', 'Blocks']
if I do the Django model is it ok if I simply do model with these columns, or do I need to do a proper database with separate tables like:
Is my UML is ok or do I need to fix something?
here is link to my UML https://drawsql.app/xml-team/diagrams/football-game-stats
You don't need to manually create tables and relations in your database, Django can take care of that for you.
It has been explained in detail here
I suggest following these simple steps for building Django Model. I always did by following these steps.
Create Django Application
Add the Posts Model
Update Settings
Make Migrations
Verify Database Schema

Need guidance with creating Django based dashboard

I'm a beginner at Django, and as a practice project I would like to create a webpage with a dashboard to track investments in a particular p2p platform. They do not have a nice dashboard (but provide excel file with all data). As I see it, main steps that I need to do in this project are as follow:
Create login so that users would have account where they upload their excel files.
Make it possible to import excel file to a database
Manipulate/calculate data for it to be later used in dashboard
Create dashboard.
Host webpage.
After some struggle I have implemented point no. 2, and will deal with 1 and 5 later. But number 3 is my biggest issue now.
I'm completely unsure what I need to do, and google did not help. I need to calculate data before I can make dashboard from it. Union two of the tables, and then join them together with a third table, creating some additional needed calculated fields. Do I create a view in the database and somehow fetch this data to Django? Or do I need to create some rules so that new table would be created at the time of the import? I think having table instead of a view would have better performance. Or maybe I'm doing it completely wrong, and should take completely different approach for this kind of task? Also, is SQLite a good database for a task (I'm using it, because it was a default in Django)?
I assume for vizualization part I will need to do it with some JavaScript library, such as D3? Which then would use data from step 3.
For part 3 there is 2 way, either do these stuff and save the result in your database or you can do it when you need it using django model features like annotation, aggregation and etc.
Option 1 requires to add a table for you calculation which is Models in django.
Option 2 requires to create a doing the annotations in a view or model managers and then using them in views.
Django docs: Aggregation
Which is the best is depended on how big your data is, how complicated the calculation is and how often you need them.
And for database; SQLite is just a database for development use not the production and surly not with a lot of data and a lot of calculations. The recommended database for django is postgresql which is pretty good at handling millions and even billions of data and doing heavy calculation.
And for vizualization you should handle it on the template side which is basically HTML, CSS and JS.

How to add recommended products in django oscar dashboard

I am using django-oscar == 1.6.1 for a project.
I am trying to add recommended products to an individual product in the dashboard, currently I see that the recommended product field is empty, how do I populate it and give the ranking?
It's a streaming search field, whatever you type should search for related term in your existing products database.
For example, if you type <search_term> it would ultimately query (after several intermediate queries of substrings) & hit http://localhost:8000/dashboard/catalogue/product-lookup/?q=<search_term>, the view for which can be found here. As you can see, it searches the product titles only, if you need something else, you can always modify it.
By the looks of it, you haven't populated your products database yet, or there's something else wrong with your installation or setup.

How to know where database has changed

I have a project that looks like a simple shopping site that sells different kinds of products. For example, I have 4 models: Brand, Product, Consignment. Consignment is linked to Product, and Product is linked to Brand. To reduce count of queries to databases, I want to save current state of these models(or at least some of them). I want to do it, because I show a sidebar with brands and products. So every time when user opens some page, it will execute the query to database to get those brands and products.
But when admin add some new product or brand, I want to handle database changing and resave it. How to implement it?
Your answer is by using Cache. Cache is a method to store your objects in memory/other app like redis temporarily so that you do not need send queries to database. You can read the full description here.
Or, you can use this third party library that helps you to cache Django ORM Model. Here are the example.
Brand.objects.filter(name='stackoverlow').cache()
After doing an update to the model, you need to clear or invalidate the cache.
invalidate_model(Brand)

Django Awaiting Appoval

If you want user to submit say articles to your website but you want to approve these articles before they are added to a list of articles, how would you go about doing so?
The only method I can think of is to have 2 databases; one for 'awaiting approval' and another for 'approved and ready to be displayed'. However, my issue is whether there is a fast method to go about transferring the information between the two databases? I only know about doing this manually.
Or is there already a Django module that handles this?
Thank You for any help.
As jordi has said, add an extra field, but you might also want to write a custom manager for your table that selects posts according to status.
See the Django docs: https://docs.djangoproject.com/en/dev/topics/db/managers/ where they set up a manager that filters on sex="M" to only return Male people. This makes your code neater, and means as long as you go through the right manager you'll not have to keep remembering to test for state="Approved" all the time.
If you want to get more complex, the thing you are doing is called "Workflow" and there are django and python packages that implement this - but it gets very complex very quickly...
Just add a column to the database table called status
1 = waiting
2 = approved
3 = denied