Using same database table with two different projects Django - mysql

I'm a beginner in Django.
I would like to know how to configure two different projects to share the same database table in Django. The database I'm using is MySQL.
Let's say there's two projects, project A and project B. In project A, I already created a custom user model in it. And in project B, I want to use the custom user table from database created in project A just for the login. Means that in project A, there's registration and login for the custom user model.
In project B, there's login only that will be using the same custom user data in the database.
Do I have to redefine the same custom user model from project A in project B?
What are the configuration settings that need to be done?
Thanks in advance.

project B can't accessible table from project A. but same database can accessible to multiple projects via enabling remote access on parent project database. but you should keep some point whenever your are made a model in any project then you must add that model in remain project

Okay, somehow I managed to solve this.
Like the previous step, I did python manage.py inspectdb > models.py in project A which I already created custom user model that used for registration and login. Then, I copy that models.py file into project B and changed the custom user model generated by project A to the exact same steps when I created the custom user model in project A. Means that I did the CustomUserManager class as well as the other necessary things required when you create a custom user model(AbstractBaseUser).
Then, in the settings.py of project B, I did AUTH_USER_MODEL which somehow solve this issue.
It seems like in order to use the same custom user model in different projects with same database, we need to redefine the exact custom user model along with managed = False.

Related

When to create a module in Yii2 Advanced template?

I am little confused before starting a new project in Yii2 advanced template. So, i am asking this question.
I have done some projects in "Yii2 basic" app in which we use modules for different parts of our application like for adminpanel, api we create different folders in 'modules folder'.
I had also done a project in Yii2 advanced template it was multiapp project so we used advanced template. As we already had 'backend' and 'frontend' separated in Yii2 advanced template so we didn't created any module in 'modules' folder.
Now, i want to ask what is right approach. like in my new project we have users and products in backend so is it appropriate to create different modules for them in 'modules' folder or will it be ok if i create there controllers and models directly in backend folder.
what are the advantages of using modules folder in advanced template?
Thanks for answers in advance.
The advantage of module's use is primarly the possibilities of a resue of this components in several diffferente project. you can easly separate you common repetative functionalities in several modules and use the same code in different prject indipendently of the "template" or scaffolding you use for the single applicazione or group of applications.
Do the fact the modules are self-contained software units that consist of models, views, controllers, and other supporting components
modules are, not only usable as a sort of mini-applications, but also as a easy way for code organization and reuse.
Modules are used to reduce our work.
Example:
In most of projects have user login function like login , signup ,
forget passsword ,password reset.
If you write code for these functions as module . You can use any
project
So there is know need to write one code again and again.

How to add manage temparory data in DotnetNuke?

I am beginner in DNN. I am creating a module which provides Login, Dashboard and Add-Update Form. I have data in JSON format. I want to store it temparory while user use the website. Data will be destroy as soon as user will close the website.
Currently I have created a folder in my Solution Explorer of project in Visual Basic and created 3 .json files which stores login_info.json, basic_info.json and auth_info.json. I write json data whenever user login and I make it blank when user logout.
Above method is working fine now but I afraid it will work when I will publish this module.
Also I may have situation where I need to store image some where. I don't know how I will manage.
Can anybody please guide me?
Is this proper way to store data temparory in DNN?
Is there any other better way?
After getting one of reply for Database Suggestion
Is there any table which same as User Meta in DotnetNuke?
You use the ConnectionString that is used by DNN and access the database as you would normally.
DotNetNuke.Common.Utilities.Config.GetConnectionString()
Or you can use the Data Access Layer that the DNN Framework supplies. For that take the Christoc Templates. In there is all you need to communicate with the DB.

Yii2 Rbac not able to add new roles

In my Yii2 project previously I had worked on rbac, set it up as in the yii2 doc click here. Now I worked on different modules and I am back on rbac. Initially set it up with just sysadmin and staff. Now I want to add a new role along with the two previous roles. Which I did it auth_item table and assigned the user_id in the auth_assignmnet table to the new role created.
In my controller added the role name for which actions he can access. But still throws Forbidden Exception. Tried different things but unable to work on it..
Any solution for this?
First of all, you should modify RBAC structure using the provided authManager methods.
After adding new RBAC items manually in database or files you need to make sure cache is not keeping the old data.
Flush cache manually or call console method like
yii cache/flush-all

Different databases per user account after login in CakePHP

I want to create separate databases for different registrations.
First i was doing it via multiple sub-domain manually but now i want it to be automatic after registration when anyone sign up.
This is what am thinking to implement:
First i'll create a common database "user_databases" to just store "user email" and "user database name". So when any user login with his email then i will fetch its database name and then verify login password from users table of the fetched database.
But the problem is how will i achieve it?
Should i include the code in database.php of Config or in each model i use $useDbConfig (i don't want to use it due to some reasons)?
Are there any better methods for it? Am i thinking right to implement it?
Please help and guide.
database partitioning in cakephp is now a trivial task because of cake's event system. cakephp allows you to talk to its request and response objects early in the app startup process in form dispatch filters. markstory has written nicely about this http://mark-story.com/posts/view/using-cakephp-and-a-horizontally-sharded-database

Organizing a large number of classes under a Namespace

We are converting windows applications to browser based in .Net using Visual Studio 2010. While I'm not new to .Net, I am new to creating applications based on 3 tier architecture. I want to create classes for each table in our database and put them under a Namespace. The class name will be the same as the table name, so each class in the the Namespace would be referenced something like CompanyName.ProductName.Entity.{table name}. Now for my questions:
Is this feasable?
Would I create seperate project for each table class? Note that new table classes will be created as more programs are converted.
Does this create one huge .dll?
How do other developers access the classes I created, and where are they stored so I can reference the classes with the Using directive?
Always create the class names with individual cs file, so it will be easy to do versioning of files. It does not relate to size of dll if we keep the class in a single file or multiple files.
Create the folder structure like Project > ProductName > Classes in your solution.
Would I create seperate project for each table class?
No, don't create a separate project for each table class. That's too granular.
Does this create one huge .dll?
Each project would create a separate DLL by default (I believe you can do things with IL merge to change that.) However, each namespace does not have a direct relationship to DLLs. That is, you can have multiple namespaces in a single DLL.
What we've typically done is create a DAL library. This would be it's own project, usually named something like ProductName.Data Then within that we might have a namespace like ProductName.Data.Models or ProductName.Data.Repositories.
Namespaces are largely used to help YOU organize the code. They also help out the compiler. For example, if you have a database class named Users, and it's in XYZ.Data, you can still have a view model named Users if it's in a separate namespace, e.g. XYZ.ViewModels.
Another thing that we've done is to keep the root namespace the same across DLLs for the same product. So we recently had our database in XYZ.Data. Then we put our application specific logic in a separate DLL and named it XYZ.AppLogic We also had view models in the namespace XYZ.ViewModels.
I don't believe there are any hard/fast rules that limit the number of namespaces you have. By default, Studio will try to create a new namespace for each folder in your project. That said, I often try to avoid namespace overload, because I don't want to see something like this at the top of my files:
using XYZ.Data.Models.Accounts;
using XYZ.Data.Models.Users;
using XYZ.AppLogic.Authentication;
using XYZ.AppLogic.Users;
using XYZ.AppLogic.Settings;
using XYZ.ViewModels.UserPreferences;
However, that's more of a personal preference than anything else.
EDIT Solution View
MySolution
MyProj.Data
Models
User.cs
Account.cs
Settings.cs
Repository
UserRepository.cs
AccountRepository.cs
User.cs is my POCO (Plain Ol' CLR Object) that defines the table.
The Repository folder has things specific to my ORM (I'm using PetaPoco) which let me actually access my user data.
For example, my UserRepository might have a method
public User GetById(int id)
{
var db = new Database(<myConnectionStringName>);
return db.SingleOrDefault<User>(id);
}
That syntax is specific to PetaPoco, but it is how I separate the data object from the actual DB connection.
The simple answer that I was looking for is to create one solution with my namespace as the default namespace. For each file, create a new class, and specify the namespace in each. Thanks to all who responded.