# Path: lazysignup/models.py
# class LazyUser(models.Model):
#     user = models.OneToOneField(constants.LAZYSIGNUP_USER_MODEL, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=now, db_index=True)
#     objects = LazyUserManager()
# 
#     @classmethod
#     def get_user_class(cls):
#         related_user_field = cls._meta.get_field('user')
#         # Django < 1.9 has rel.to
#         if hasattr(related_user_field, 'rel'):
#             rel_to = related_user_field.rel.to if related_user_field.rel else None
#         elif hasattr(related_user_field, 'remote_field'):
#             rel_to = related_user_field.remote_field.model if related_user_field.remote_field else None
#         return rel_to
# 
#     def __str__(self):
#         return '{0}:{1}'.format(self.user, self.created)


import datetime
from django.conf import settings
from django.contrib import admin
from .models import LazyUser


@admin.register(LazyUser)
class LazyUserAdmin(admin.ModelAdmin):
    list_display = ('user', 'created',)
    actions = ('cleanup_lazyusers',)

    def cleanup_lazyusers(self, request, queryset):
        delete_before = datetime.datetime.now() - datetime.timedelta(
            seconds=settings.SESSION_COOKIE_AGE)
        old_users = queryset.filter(user__last_login__lt=delete_before)
        count = old_users.count()

        for lazy_user in old_users:
            # iterate so any .delete() methods get called and signals are sent

# Path: lazysignup/models.py
# class LazyUser(models.Model):
#     user = models.OneToOneField(constants.LAZYSIGNUP_USER_MODEL, on_delete=models.CASCADE)
#     created = models.DateTimeField(default=now, db_index=True)
#     objects = LazyUserManager()
# 
#     @classmethod
#     def get_user_class(cls):
#         related_user_field = cls._meta.get_field('user')
#         # Django < 1.9 has rel.to
#         if hasattr(related_user_field, 'rel'):
#             rel_to = related_user_field.rel.to if related_user_field.rel else None
#         elif hasattr(related_user_field, 'remote_field'):
#             rel_to = related_user_field.remote_field.model if related_user_field.remote_field else None
#         return rel_to
# 
#     def __str__(self):
#         return '{0}:{1}'.format(self.user, self.created)


# Path: lazysignup/admin.py
import datetime
from django.conf import settings
from django.contrib import admin
from .models import LazyUser



@admin.register(LazyUser)
class LazyUserAdmin(admin.ModelAdmin):
    list_display = ('user', 'created',)
    actions = ('cleanup_lazyusers',)

    def cleanup_lazyusers(self, request, queryset):
        delete_before = datetime.datetime.now() - datetime.timedelta(
            seconds=settings.SESSION_COOKIE_AGE)
        old_users = queryset.filter(user__last_login__lt=delete_before)
        count = old_users.count()

        for lazy_user in old_users:
            # iterate so any .delete() methods get called and signals are sent

            lazy_user.user.delete()