How to create multiple user models with choices? - django-models

I have different types of users and have created models for each user type.signup is different for everyone.. now i want to select models at signup page according to user choices or type. for example if someone selects student then a signup page with different form fields should appear.like that i have to do for each user type.is it possible to go by the choice option with if else method inside a class and choosing the different user models according to choices??

It's not clear whether your user classes share a common base class, but I think that would be essential. The documentation has a lot of information about using a custom user model. But, I recommend reading this post, and going with Option 2: Using One-To-One Link With a User Model (Profile)
What is a One-To-One Link? It is a regular Django model that’s gonna
have it’s own database table and will hold a One-To-One relationship
with the existing User Model through a OneToOneField.
When should I use a One-To-One Link? You should use a One-To-One Link
when you need to store extra information about the existing User Model
that’s not related to the authentication process. We usually call it a
User Profile.

Related

update availableOptions for multiselect Picklist through Apex trigger

I have created a multiselect picklist which shows the list of users on a custom object. I want to update the available values on this picklist through trigger on User object whenever there is a new user created. I do not want to update the Chosen value. Also this is a field on a lightning page, not a vf or lwc or aura component. Is it a possible requirement? Please let me know if any further information required.
Field on Lightning page
enter image description here
Dynamically updating your org's schema based on data changes is both generally a bad idea and much more difficult than it sounds.
Your trigger would have to use Asynchronous Apex, such as a Queueable class, to call the Metadata API or Tooling API to update the picklist values. To do so, it must be authenticated as an administrator, so you'd also need to set up a Named Credential and authorize it as an administrator. And then you'd have to write the moderately complex code to actually create picklist entries based on Users, decide what to do when existing Users/picklist entries are deactivated, and so on.
It is generally a better pattern to implement a custom UI component (like a Lightning Web Component) where you need to present a dynamic picklist-style interface that's driven by data.

Best practice for loading non model data in ExtJS

Let's assume that I have 2 tables in my database, a user table and a folder table. They are matched by two models (beans) in my backend java code and similarly by to models in my extjs client side. Using viewmodel architecture, I want to create a form that shows the username and the amount of folders they have created using viewmodel bindings. Each folder in the database has a CREATE_USER_ID field that contains the id of the user that created the folder. How do I go about loading the required data?
Viewmodels are not designed to load data directly (and not designed to load non model data at all). You've got two options:
Go model (recommended). Two sub-options:
Add folder_amount field to your client side user model. On the server side this does not necessarily need to be added as well as you can adjust your API feeding data to client to add that field dynamically.
If you want to keep your client models exactly matching their server mates, use viewmodel in conjunction with associations (see example here, scroll down to Associations) to load folders themselves, though in the UI only show the amount of them. Mind that you don't need to load all folder fields but just their IDs.
Stick to your own fancy non model approach, but this won't have anything to do with viewmodel bindings. This may be, for example, making an AJAX call to retrieve the number of folders when user data is rendered in the UI.

Role based views in extjs4 mvc

My application has different views for different roles like (admin or standard user).I don't know how can i implement it with extjs4 MVC. Examples of extjs4 documentation consider that application has only one role like standard user so they create one app.js file that manage application but if application has many roles i don't know how can i implement different views for different users.
One matter is i have two app.js files in the application and after i get user role in the server i load appropriate app.js file to use appropriate views,controllers,models,stores and so on.
Is this matter true?
This is a rather standard question that comes up so many times and the answer is always the same:
Access Control belongs to the Server where no user can manipulate it
Simply don't provide a View / a model / a controller to a user where he has no access to
With that in mind it doesn't matter if you have one app or ten.
And because Access Control is nothing that belongs to the frontend there is no implementation within ExtJS.
Update -> Hide UI elements
A ready to go approach would be the use of Ext.direct. This provide the application with a API that can be modified based on custom access of the current user and can then be checked by the frontend.
HowTo:
Create the API based on the user session and check on the Clientside like
if(Booking) {
if (Booking.Create) {
// has access
}
}
or as one line
{
xtype: 'button',
hidden: !(Booking && Booking.Create)
}
This is just a simple example how easy this could be done!
update
This Link helped the op

asp.net mvc - extending the registration page (membership) versus new user table (profile) - are they the same thing?

I want to store additional information on my users (address, phone).
Should I extend the registration page on the sample mvc template or should I set up a separate "profile" table and have that be a separate page?
It seems nice to do it on the registration page, but I am not sure if there are issues playing around with the "aspnet_"... tables that are setup for registration.
Any suggestions? I would like to use LINQ to SQL as well if possible but I see the default implementation is using
System.Web.Security.membership
You could also consider creating custom Membership Provider.
In terms of usability, you always want your registration to be as short as possible. It's a good habit to get into, even if the application that you are currently developing is not a commercial application. So the best way to design the front end would be to have as little information required from the visitor for registration and then have a separate "profile" page once they are logged in after registration is successful.
In terms of database design, keeping the profile in a separate table is once again recommended.
Once you've done this, you can either treat the profile information as just another set of information that the user can edit OR you can implement ProfileProvider. All you need to do is implement GetPropertyValues and SetPropertyValues.
public class MyProfileProvider : ProfileProvider
{
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
{
}
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{
}
}

cakephp - how can I forward data in the controller to another controller?

I have a signup form posting to my customers_controller, but now they want the signup form to take payment information too. I have a payment_controller, After saving the new user I'd like to forward the payment post data to the action in the payment_controller.
How do I do that?
I would recommend that you put the actual logic for payment into a payment or invoices model. Doing that, you can either link the two models (allowing you to make a $this->Customer->Payment->process_charge(..) call), or you can define the $uses attribute in the Customers controller to allow calls to the Payment model.
I'm also a proponent of "fat models, skinny controllers" school of thought, in part due to this situation. I try to think of the controller as being in charge of the actual http request (access control, workflow properties, etc.) and letting the models do most of the heavy lifting.
I suggest that in the registration action in the users controller, when the user is registered (and logged in) you redirect to the payments controller where you use a normal payment model and view that self posts there. The way to communicate from the end of one action to another through a redirect would be to build the url. You do not need to pass along the user information however, since the Payments controller should be able to grab the user's id when needed, ie :
$this->data['Payment']['user_id'] = $this->Auth->user('id');
$this->Payment->create($this->data);
if ($this->Payment->save()) {
// etc
Assuming Customers and Payments are related in some fashion, there's no reason you couldn't record payment information in your cusomters_controller.
$this->Customer->Payment->create()...
There's no rule that says you must use one controller for each model. In fact, that won't work in the vast majority of real-world applications like you're experiencing now.
I normally segregate my controllers by logical functionality groupings rather than trying to pair them up to models. In your case, I would build an accounts_controller (even if I have no accounts table) and put the login, registration, logout, profile editing, etc in that controller.
I find this sort of organization makes the application easier to maintain, and it makes for more logical paths for end users as well.
Ultimately I decided it was foolish to try and move data to another controller. I created a payment component which handles requests from any controller.

Resources