diff --git a/backend/account/admin.py b/backend/account/admin.py index 22f080d..b223804 100644 --- a/backend/account/admin.py +++ b/backend/account/admin.py @@ -112,7 +112,7 @@ class SecurityBreachAttemptAdmin(ModelAdmin, ImportExportModelAdmin): compressed_fields = True warn_unsaved_form = True change_form_template = 'loction_chagne_form.html' - list_display = ['ip', 'country', 'region_name', 'city', 'zip_code', 'isp', 'created_at', 'trys', 'display_viewd'] + list_display = ['ip_address', 'country', 'region_name', 'city', 'zip_code', 'isp', 'created_at', 'trys', 'display_viewd'] def change_view(self, request, object_id, form_url='', extra_context=None): extra_context = extra_context or {} @@ -120,7 +120,7 @@ class SecurityBreachAttemptAdmin(ModelAdmin, ImportExportModelAdmin): if obj and obj.lat and obj.lon: m = Map(location=[obj.lat, obj.lon], zoom_start=10) - Marker([obj.lat, obj.lon], popup=f"Location: {obj.ip}").add_to(m) + Marker([obj.lat, obj.lon], popup=f"Location: {obj.ip_address}").add_to(m) map_html = m._repr_html_() extra_context['map_html'] = map_html return super().change_view(request, object_id, form_url, extra_context) diff --git a/backend/account/migrations/0022_remove_securitybreachattemptmodel_ip_and_more.py b/backend/account/migrations/0022_remove_securitybreachattemptmodel_ip_and_more.py new file mode 100644 index 0000000..0774469 --- /dev/null +++ b/backend/account/migrations/0022_remove_securitybreachattemptmodel_ip_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.1.2 on 2025-02-20 22:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0021_securitybreachattemptmodel_ip'), + ] + + operations = [ + migrations.RemoveField( + model_name='securitybreachattemptmodel', + name='ip', + ), + migrations.AddField( + model_name='securitybreachattemptmodel', + name='ip_address', + field=models.CharField(default='', max_length=100, verbose_name='آدرس آی\u200cپی'), + preserve_default=False, + ), + ] diff --git a/backend/account/models.py b/backend/account/models.py index 8dcad75..8a3c264 100644 --- a/backend/account/models.py +++ b/backend/account/models.py @@ -217,7 +217,7 @@ def get_location_from_ip(ip_address): return None class SecurityBreachAttemptModel(models.Model): - ip = models.CharField(max_length=100, verbose_name="آدرس آی‌پی") + ip_address = models.CharField(max_length=100, verbose_name="آدرس آی‌پی") country = models.CharField(max_length=40, verbose_name="کشور", blank=True, null=True) region_name = models.CharField(max_length=40, verbose_name="منطقه", blank=True, null=True) city = models.CharField(max_length=40, verbose_name="شهر", blank=True, null=True) @@ -231,7 +231,7 @@ class SecurityBreachAttemptModel(models.Model): def save(self, *args, **kwargs): if not self.id: - location_data = get_location_from_ip(self.ip) + location_data = get_location_from_ip(self.ip_address) if location_data: self.country, self.region_name, self.city, self.zip_code, self.lat, self.lon, self.isp = location_data diff --git a/backend/core/views.py b/backend/core/views.py index ed76744..ee1b6d0 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -275,7 +275,7 @@ class FakeAdminLoginView(View): print(ip) print(len(ip)) print(type(ip)) - hacker, created = SecurityBreachAttemptModel.objects.get_or_create(ip=ip) + hacker, created = SecurityBreachAttemptModel.objects.get_or_create(ip_address=ip) return render(request, 'admin/fake_login.html', self.get_context(request)) def post(self, request): @@ -285,7 +285,7 @@ class FakeAdminLoginView(View): else: ip = request.META.get("REMOTE_ADDR") print(ip) - hacker, created = SecurityBreachAttemptModel.objects.get_or_create(ip=ip) + hacker, created = SecurityBreachAttemptModel.objects.get_or_create(ip_address=ip) hacker.trys += 1 hacker.save() messages.error(request, "Please correct the error below.")