Notification api lari chiqarildi

This commit is contained in:
2025-11-27 00:40:27 +05:00
parent 900f23e5f6
commit e8e900c393
14 changed files with 265 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
from django.contrib import admin
from unfold.admin import ModelAdmin
from core.apps.accounts.models import SearchHistory, UserLike
from core.apps.accounts.models import SearchHistory, UserLike, UserNotification, Notification
@admin.register(SearchHistory)
@@ -18,3 +18,19 @@ class UserLikeAdmin(ModelAdmin):
"id",
"__str__",
)
@admin.register(UserNotification)
class UserNotificationAdmin(ModelAdmin):
list_display = (
"id",
"__str__",
)
@admin.register(Notification)
class NotificationAdmin(ModelAdmin):
list_display = (
"id",
"__str__",
)

View File

@@ -0,0 +1,49 @@
# Generated by Django 5.2.7 on 2025-11-26 12:24
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0006_rename_address_name_business_address_and_more'),
]
operations = [
migrations.CreateModel(
name='Notification',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('title', models.CharField(max_length=255, verbose_name='Title')),
('description', models.TextField(verbose_name='Description')),
('notification_type', models.CharField(choices=[('System', 'System'), ('Another', 'Another')], max_length=255, verbose_name='Type')),
('long', models.FloatField(verbose_name='Long')),
('lat', models.FloatField(verbose_name='Lat')),
],
options={
'verbose_name': 'Notification',
'verbose_name_plural': 'Notifications',
'db_table': 'notification',
},
),
migrations.CreateModel(
name='UserNotification',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('is_read', models.BooleanField(default=False, verbose_name='Read')),
('notification', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.notification', verbose_name='Notification')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User')),
],
options={
'verbose_name': 'User Notification',
'verbose_name_plural': 'User Notifications',
'db_table': 'user_notification',
},
),
]

View File

@@ -5,3 +5,4 @@ from .address import * # noqa
from .business import * # noqa
from .user_like import * # noqa
from .search_history import * # noqa
from .notification import * # noqa

View File

@@ -3,6 +3,7 @@ from django_core.models.base import AbstractBaseModel
from django.utils.translation import gettext_lazy as _
from core.apps.accounts.choices import NotificationType
from django.contrib.auth import get_user_model
from model_bakery import baker
class Notification(AbstractBaseModel):
@@ -12,6 +13,10 @@ class Notification(AbstractBaseModel):
long = models.FloatField(verbose_name=_("Long"))
lat = models.FloatField(verbose_name=_("Lat"))
@classmethod
def _baker(cls):
return baker.make(cls)
def __str__(self):
return str(self.pk)
@@ -26,6 +31,10 @@ class UserNotification(AbstractBaseModel):
notification = models.ForeignKey(Notification, verbose_name=_("Notification"), on_delete=models.CASCADE)
is_read = models.BooleanField(verbose_name=_("Read"), default=False)
@classmethod
def _baker(cls):
return baker.make(cls)
def __str__(self):
return str(self.pk)