First time here? Check out the FAQ!
1

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
51
kristof
asked 2015-02-24 04:00:20 -0500, updated 2015-02-24 13:15:27 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

1

what type of database you use ???

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

Comments

postgresql

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

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

Comments

add a comment see more comments