How to load values related to selected multiple options in Django - django

Thank you all for always willing to help.
I have a Django app with countries and state choices fields. However, I have no idea whatsoever on how to load the related states for each country. What I mean here is, if I choose "Nigeria" in the list of countries, how can I make all Nigerian states to automatically load in the state choice field?

You have to create many to many field state table, then you can multiple select state as per country.
this feature available on django- country package or django- cities package.

Related

PowerBI conditional/advanced filtering - is it possible?

I have a large set of Equipment data that contains both geographical equipment location and company ownership data.
The geographical data has a hierarchy based on size (i.e. continent, country, county, city, street), so the filters for that data is easy.
The company data details which companies own which pieces of equipment, but it’s not directly related to geography, so multiple companies can own equipment on a single site. So I can filter by company name nicely.
As the data is common to both company and location, I’d like to combine in to one dashboard, but with two filters. I’d love to be able to filter by location OR filter by Company but ideally, I don’t want the users to try to use both filters at the same time. Is it possible to have some logic built in so that if a user selects a location filter, it clears any Company filters selected and vice versa so that if a user selects a company filter any location filters already selected are cleared.
Is this possible and if so, how would I go about it?
Thanks in advance,
Dofus
Using buttons and bookmarks you can clear filters and toggle the visibility of slicers.

Conditional Relationships between Two Tables in Django?

The following image shows a rough draft of my proposed database structure that I will develop for Django. Briefly, I have a list of ocean Buoys which have children tables of their forecast conditions and observed conditions. I'd like Users to be able to make a log of their surf sessions (surfLogs table) in which they input their location, time of surf session, and their own rating.
I'd like the program to then look in the buoysConditions table for the buoy nearest the user's logged location and time and append to the surfLog table the relevant buoyConditions. This will allow the user to keep track of what conditions work best for them (and also eventually create notifications for the user automatically).
I don't know what the name for this process of joining the tables is, so I'm having some trouble finding documentation on it. I think in SQL it's termed a join or update. How is this accomplished with Django?
Thanks!

Row level security in Power Bi

I am not able to implement row level security to my report. I have tried different methods on google and Microsoft forums but all in vain. Could you please help?
I have a dataset name "Cases" which have details of all cases logged into system with its country.
Then I have dataset name "Escalations" with details of the all the escalations along with its country.
Then there is one more table called "Country Mapping" which contains all the countries mapped with their Regions and Region Manager.
I have already prepared a report showing Global /Regional numbers But now people want to restrict the data according to its own territory.
Example :- Some want to see global data and some are responsible for a particular country. I know RLS can help me with this. I have tried to make two tables one with Username and country responsible and other one with just usernames and names.
I have made a relationship between all these tables. But the problem with the code is, like if I am the admin of the report then I need to manually add myself in the country responsible for every country. Like 146 countries .
Is there any better way to do this?

Django create a view to generate a receipt

I want to create a small app that creates a kind off receipt record in to a db table, from two other tables. very much like a receipt from a grocery store where a cashier makes a sell and the ticket contains multiple items, calculates a total and subtotal and return values to the database. I currently have 3 tables: the Ticket table where i would like to insert the values of all calculations and ticket info, the services table that acts like an inventory of services available. this has the service name and price for each service and my responsible table that has a list of "cashiers" or people that will make the sale and their percentage for their commissions, i have the views to create , edit and delete cashier's and services.
What I don't have is a way to create the ticket. I am completely lost. can you guys point me in to the correct path on what to look for. i am learning to program son i don't have a lot of knowledge in this if its even possible. i don't need the system to print i just want to have all record stored this way later on i can expand on it and create reports of sold items and who sold them and how much commissions each seller has won.
You need to create relationships to two other models (tables) from the Ticket model (table). Luckily you don't have to create the relations in the database tables itself. Use django model's Foreign key fields to accomplish this. Here is the documentation link:
Django Models
You may need to read it several times to get the concepts thoroughly.

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)