Ask Your Question
1

Spambot registrered 1000 users - command to delete last 1000 users?

asked 2015-02-24 04:00:20 -0500

kristof gravatar image

updated 2015-02-24 13:15:27 -0500

Some spambot has registrered 1000 users over the last month, is there some command to delete the last 1000 users at once? For example, a SQL command that deletes the content after some date?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-03-07 15:17:33 -0500

Evgeny gravatar image

updated 2015-03-07 15:21:57 -0500

Firstly, to prevent future spam enable "premoderation" in the settings -> content moderation section. Enable required email confirmation, this will reduce number of spammers at the site.

Answering your question: Delete users via the django shell. (Note: Before doing this back up your database)

Suppose that the last non-spammer user has id number 256

python manage.py shell
>>> from askbot.models import User
>>> users = User.objects.filter(id__gt=256)
>>> users.delete()
>>> exit()

This will delete the users and all the content they have posted.

Another option is to delete all content and block users (this will mark the content as deleted):

 #select the users as above
 >>> admin = User.objects.get(id=1) #assuming that admin has user id 1
 >>> for user in users:  #iterate through users that you want to block/delete
 ...     admin.delete_all_content_authored_by_user(user) #mark all content as deleted
 ...     user.set_status('b') #block user
 ...     user.save()
 >>> exit()
edit flag offensive delete link more
1

answered 2015-02-24 10:35:19 -0500

Sindbad gravatar image

what type of database you use ???

edit flag offensive delete link more

Comments

postgresql

kristof gravatar imagekristof ( 2015-02-24 13:14:27 -0500 )edit

No. To do it just once you would simply write the delete statement for the table you want to cascade. DELETE FROM some_child_table WHERE some_fk_field IN (SELECT some_id FROM some_Table); DELETE FROM some_table;

Sindbad gravatar imageSindbad ( 2015-03-02 14:31:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-02-24 04:00:20 -0500

Seen: 507 times

Last updated: Mar 07 '15