Help on architecture of User layout configuration system

26 views
Skip to first unread message

Devender Kumar

unread,
May 13, 2019, 6:28:47 AM5/13/19
to Django users
Hi,
I want to make a web app in which user has rights to configure his layout.Means each user can configure his layout according to his choice and work 
Like how many fields can his form have how many field he want to see in table view of individual record view . configure theme color of his own choice .
all these type of settings he can do for his own use.
Can any one help me with this type of architecture.
Thank you
Devender 

Chetan Ganji

unread,
May 13, 2019, 6:47:28 AM5/13/19
to django...@googlegroups.com
My 2 cents - 

You will have to store the user preferences in a settings file on the server. I would suggest to use a JSONField for the same if you are using the PostgrSQL. Otherwise you will have to create a separate model. Saving settings in model will take more efforts. Using JSON for this would be perfect. Store this JSON on the User Model in the django, so you are basically adding an extra JSONField to the user model in django. If you store this data on a different model, you will end up writing one extra sql/orm query to fetch the settings. So, save yourself that trouble and store the settings on the user model.

Whatever user can configure, create respective key value pairs for the same. 

Then in every template where these settings would be required, access them using the variable request.user.settings (assuming you named it settings). 
In the templates, wherever the user can customize his view, you would write the if blocks to check if the current user has selected the respective settings or not. 
Accordingly they would be rendered DYNAMICALLY.

I hope it helps :)


Regards,
Chetan Ganji
+91-900-483-4183


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b9332431-bb74-416d-b5e6-a54db73c1b56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Devender Kumar

unread,
May 13, 2019, 7:08:08 AM5/13/19
to Django users
Thank you for your suggestion 
I am using PostgreSQL
You have successfully saved the layout but I am talking about the dynamics forms fields which will be used for form submission how you are looking to store the values of 1000's of records entered after that in those fields.
that's why I was looking for more efficient way (as I know this solution already ignore the fact that storing the json of record values too) as it might decrease the efficiency of the system.

Chetan Ganji

unread,
May 15, 2019, 12:04:03 PM5/15/19
to django...@googlegroups.com
This one is interesting. I was also looking for the solution of the same problem.

If I understand correctly, the problem with forms is - 
User can choose the name of the field and the type of the fields e.g. IntegerField(). FloatField(), etc. Kind of a form that is generated using a form :P 
More like a Form Builder App which will help users create DYNAMIC FORMS.
Am I correct?

We could create a form for that with 2 inputs elements. 
One input to enter the name of the field. 
Second would be a dropdown (select html element) with the type of the model fields that django models.Model has. We can also add select dropdown for constraints.
Store the values of these two in a JSONField(). This part is simple and possible.

The real challenge is - 
How to turn them into models and store the actual data?

Solution 1
That is also simple. We could create a default string that resembles the source code of a model class of a django model.
and create the code for it by writing the if clauses for diff fields of the models and create a string for the same. Then write this string to a .py file.
e.g. 

"class BaseModel(models.Model):
created = models.DateTimeField(auto_now=False, auto_now_add=True,)
updated = models.DateTimeField(auto_now=True, auto_now_add=False,)"


The Problem with this approach is app will end up with lots of .py files that has diff models. 
Making migrations and Migrating will also be a pain point. 
Making any migrations will require stopping and restarting the server (nginx+gunicorn), that is not possible in a production environment. 
Will have to restart the server for every new form created and migrated.

Not a good idea to do this.

Solution 2
As each form/model would have a separate schema, using a JSONField() makes sense here. 
As we are storing forms in JSONField(), store the data also in the JSONField(). 
This wont require making any models/migrations and migrating the database. Also server restarts are not required at all.

This is more feasible solution and will be easier approach than the earlier one.

However, making the forms populate/reder dynamically from the stored json field and validating them dynamically according to their schema NEEDS SOME R&D.
Give it a try and share the results with me. 

I hope it was worth your time :) 


Regards,
Chetan Ganji
+91-900-483-4183

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages