Relative Content

Tag Archive for djangodjango-modelsdjango-rest-framework

django payment, user balance

for example, I have a simple website where there is a list of posts, they are of two types: paid and free, paid ones can be purchased by authorized users and then they can read it, free ones can be read by anyone, after registration, all authorized users will have their own balance, there will be a payment system, and each authorized user can deposit at least 5$, after payment, so that the amount he deposited will be credited to his account, how can I implement this and what technologies do I need to use and what should I pay attention to?

What is the correct way to query a many to many relationship in Django efficiently?

I probably haven’t phrased this question correctly so apologies. Also probably why I cannot find much information when I google it. Anyway I have a Django project that I am using to create an API using Django Rest Framework. For this problem I have 2 models that are relevant. A Product model and an Offer model (slightly pseudocode so ignore any missing fields).

Pure SQL from postgres to django

We have a pure SQL in postgres that groups the instance visits registered in that table grouped by country, what I need is to pass this pure query to django queryset to get the same result

Design User class in Django

I use the AbstractUser class to extend my User class. In my User class, there are currently 3 roles: Admin, Lecturer and Alumni. I can use is_superuser, is_staff to solve the problem, however, in the future there may be more roles appearing and if I use the above method it will not be possible to add more roles better. But if I use the additional field role = models.IntegerField(choices=Role.choices, default=Role.ALUMNI) it looks fine. But when using superuser, is_superuser = True and the user’s role is Alumni.
By the way, I’m working on a project using django, rest_framework. I want Users with the role of Lecturer to be created by the Admin and set a default password, and after 24 hours from the time of account creation, if the Lecturer does not change the password, the account will be locked and the Admin will have to reopen for Lecturer. I wrote two functions save and check_password_expiry but I’m not sure if it works as I want.
Can someone solve my current problem, please?