First time here? Check out the FAQ!

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

  • retag add tags

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?

kristof's avatar
asked 2015-02-24 04:00:20 -0600, updated 2015-02-24 13:15:27 -0600
edit flag offensive 0 remove flag close merge delete


add a comment see more comments

2 Answers


what type of database you use ???

Sindbad's avatar
answered 2015-02-24 10:35:19 -0600
edit flag offensive 0 remove flag delete link



kristof's avatar kristof (2015-02-24 13:14:27 -0600) 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's avatar Sindbad (2015-03-02 14:31:49 -0600) edit
add a comment see more comments

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 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
 >>> exit()
Evgeny's avatar
answered 2015-03-07 15:17:33 -0600, updated 2015-03-07 15:21:57 -0600
edit flag offensive 0 remove flag delete link


add a comment see more comments