hello guys so i made this website that intergrate with my router to manage the user inside it,but i have this question i want to ask
so my website only visualise the data that it got from the router and i have this voucher system to give out voucher to the user
to access the network as right now i save this voucher in my database but due to each of the voucher data that it i save to the database and from the database it display to the web, it all from data that it got from the router<-- and here
come the problem is that the data is not valid because if the admin access the router and delete one of the voucher profile it will cause and error,because the voucher in database is been deleted from the router,
is there any way i can do this so that i dont need to use database to save this? thanks
you can try storing it in files. but its not reliable, and not as efficient as storing in database. its also not ass fast. it takes more time to update file than update database. so db is your best and only option.
Related
I am planning to store all my user activity logs( like user logged in, password changed etc)in a redis database instead of the main database used in the project.
For example:
class MyLogModel(models.Model):
log_msg = models.CharField(..)
Then I usually create the table like this
MyLogModel.objects.create(log_msg='msg')
My question is can I do the same with Redis?
If not redis how can I optimize my database with django since over the time it will have so many data which might make the database slower.
OR another option deleting the activity logs older than 1 month something like this would be better ?
OR Is there any better approach for this scenario ?
I have a Django project. Some data is restored in the Model database. But in the web, there is some function to delete such data.
However, I don't want to complete delete such data for possible further usage like statistics. How could deal with such issues normally? I can think about transferring such data to another Model database before deleting, but is it too complicated? Or any other suggestion?
I'm developing a small website with Flask & Flask-Login. I need an admin view to monitor all user's online status. I added an is-online column in user db collection and try to update it. But I didn't find any callbacks to handle session expires. How to solve it or any better idea?
Thanks!
FYI, Counting Online Users with Redis | Flask (A Python Microframework) - http://flask.pocoo.org/snippets/71/.
You could get away with checking if users last activity time is bigger(older) than session life time.
if that's the case, you will go on an update their is_online status.
the way i have handled the problem in my application was, since i had a last_activity field in db for each user, to log when they have done what they have done, i could check that value vs session life time.
One very crude method is to create a separate stack that pushes and pops when a user logs in. Assuming that session id and userid on your db is not tied together (i.e., you have separate session id and user id), you can maintain a ledger of sorts and push and pop as sessions are created and destroyed.
You will have to put special emphasis on users running multiple sessions on multiple devices...which is why i put a caveat saying this is a rather crude method.
My django application need to collect user data(name age country etc) based on his email domain( 'gmail' as in xyz#gmail.com).I wist to create a new table every time i encounter a new email domain.
Can this be done in django ?
This is a bad idea. Your tables would all have the same structure. All of your data should be stored in a single table, with a domain column to keep the data separate. Why would you want a different table for each domain? Whatever reason you have, there's a better way to do it.
This idea goes against everything in the design of the relational database, and the Django ORM on top of it.
I have an authentication backend based off a legacy database. When someone logs in using that database and there isn't a corresponding User record, I create one. What I'm wondering is if there is some way to alert the Django system to this fact, so that for example I can redirect the brand-new user to a different page.
The only thing I can think of is adding a flag to the users' profile record called something like is_new which is tested once and then set to False as soon as they're redirected.
Basically, I'm wondering if someone else has figured this out so I don't have to reinvent the wheel.
I found the easiest way to accomplish this is to do exactly as you've said. I had a similar requirement on one of my projects. We needed to show a "Don't forget to update your profile" message to any new member until they had visit their profile for the first time. The client wanted it quickly so we added a 'visited_profile' field to the User's profile and defaulted that to False.
We settled on this because it was super fast to implement, didn't require tinkering with the registration process, worked with existing users, and didn't require extra queries every page load (since the user and user profile is retrieved on every page already). Took us all of 10 minutes to add the field, run the South migration and put an if tag into the template.
There's two methods that I know of to determine if an object has been created:
1) When using get_or_create a tuple is returned of the form (obj, created) where created is a boolean indicating obviously enough whether the object was created or not
2) The post_save signal passes a created paramater, also a boolean, also indicating whether the object was created or not.
At the simplest level, you can use either of these two hooks to set a session var, that you can then check and redirect accordingly.
If you can get by with it, you could also directly redirect either after calling get_or_create or in the post_save signal.
You can use a file-based cache to store the users that aren't yet saved to the database. When the user logs in for the second time, you can look in the cache, find the user object, and save it to the database for good.
Here's some info on django caching: http://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs
PS: don't use Memcached because it will delete all information in the situation of a computer crash or shut down.