Added first version of models
This commit is contained in:
parent
03eb894602
commit
5e8e4bab9e
@ -1,3 +1,35 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from .models import (User, PublicationCache, NotificationCache, FollowerCache,
|
||||||
|
FollowingCache, MessageCache)
|
||||||
|
|
||||||
# Register your models here.
|
@admin.register(User)
|
||||||
|
class UserAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("username", "pds_url", "access_token")
|
||||||
|
|
||||||
|
@admin.register(PublicationCache)
|
||||||
|
class PublicationCacheAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("user", "author", "content", "published_at", "is_unread")
|
||||||
|
list_filter = ("is_unread",)
|
||||||
|
search_fields = ("author", "content")
|
||||||
|
|
||||||
|
@admin.register(NotificationCache)
|
||||||
|
class NotificationCacheAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("user", "type", "content", "created_at", "is_unread")
|
||||||
|
list_filter = ("type", "is_unread")
|
||||||
|
search_fields = ("type", "content")
|
||||||
|
|
||||||
|
@admin.register(FollowerCache)
|
||||||
|
class FollowerCacheAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("user", "follower_name", "followed_at")
|
||||||
|
search_fields = ("follower_name",)
|
||||||
|
|
||||||
|
@admin.register(FollowingCache)
|
||||||
|
class FollowingCacheAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("user", "following_name", "followed_at")
|
||||||
|
search_fields = ("following_name",)
|
||||||
|
|
||||||
|
@admin.register(MessageCache)
|
||||||
|
class MessageCacheAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ("user", "sender", "content", "sent_at", "is_unread")
|
||||||
|
list_filter = ("is_unread",)
|
||||||
|
search_fields = ("sender", "content")
|
||||||
|
122
src/core/migrations/0001_initial.py
Normal file
122
src/core/migrations/0001_initial.py
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
# Generated by Django 5.1.3 on 2024-11-14 16:15
|
||||||
|
|
||||||
|
import django.contrib.auth.models
|
||||||
|
import django.contrib.auth.validators
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('auth', '0012_alter_user_first_name_max_length'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='User',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||||
|
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||||
|
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||||
|
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
|
||||||
|
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
|
||||||
|
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
|
||||||
|
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
||||||
|
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||||
|
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||||
|
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||||
|
('pds_url', models.URLField(blank=True, null=True, verbose_name='PDS URL')),
|
||||||
|
('access_token', models.CharField(blank=True, max_length=500, null=True, verbose_name='Auth Token')),
|
||||||
|
('refresh_token', models.CharField(blank=True, max_length=500, null=True, verbose_name='Refresh Token')),
|
||||||
|
('token_expires_at', models.DateTimeField(blank=True, null=True)),
|
||||||
|
('groups', models.ManyToManyField(blank=True, related_name='custom_user_set', to='auth.group')),
|
||||||
|
('user_permissions', models.ManyToManyField(blank=True, related_name='custom_user_permissions_set', to='auth.permission')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'user',
|
||||||
|
'verbose_name_plural': 'users',
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
managers=[
|
||||||
|
('objects', django.contrib.auth.models.UserManager()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='PublicationCache',
|
||||||
|
fields=[
|
||||||
|
('id', models.CharField(max_length=255, primary_key=True, serialize=False, verbose_name='Publication ID')),
|
||||||
|
('content', models.TextField(verbose_name='Content')),
|
||||||
|
('author', models.CharField(max_length=255, verbose_name='Author')),
|
||||||
|
('published_at', models.DateTimeField(verbose_name='Published At')),
|
||||||
|
('is_unread', models.BooleanField(default=True, verbose_name='Unread')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cached_publications', to='core.user')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Publication Cache',
|
||||||
|
'verbose_name_plural': 'Publications Cache',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='NotificationCache',
|
||||||
|
fields=[
|
||||||
|
('id', models.CharField(max_length=255, primary_key=True, serialize=False, verbose_name='Notification ID')),
|
||||||
|
('content', models.TextField(verbose_name='Content')),
|
||||||
|
('type', models.CharField(max_length=50, verbose_name='Type')),
|
||||||
|
('created_at', models.DateTimeField(verbose_name='Created At')),
|
||||||
|
('is_unread', models.BooleanField(default=True, verbose_name='Unread')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cached_notifications', to='core.user')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Notification Cache',
|
||||||
|
'verbose_name_plural': 'Notifications Cache',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='MessageCache',
|
||||||
|
fields=[
|
||||||
|
('message_id', models.CharField(max_length=255, primary_key=True, serialize=False, verbose_name='Message ID')),
|
||||||
|
('sender', models.CharField(max_length=255, verbose_name='Sender')),
|
||||||
|
('content', models.TextField(verbose_name='Content')),
|
||||||
|
('sent_at', models.DateTimeField(verbose_name='Sent At')),
|
||||||
|
('is_unread', models.BooleanField(default=True, verbose_name='Unread')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cached_messages', to='core.user')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Message Cache',
|
||||||
|
'verbose_name_plural': 'Messages Cache',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='FollowingCache',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('following_id', models.CharField(max_length=255, verbose_name='Following ID')),
|
||||||
|
('following_name', models.CharField(max_length=255, verbose_name='Following Name')),
|
||||||
|
('followed_at', models.DateTimeField(verbose_name='Followed At')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cached_following', to='core.user')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Following Cache',
|
||||||
|
'verbose_name_plural': 'Following Cache',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='FollowerCache',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('follower_id', models.CharField(max_length=255, verbose_name='Follower ID')),
|
||||||
|
('follower_name', models.CharField(max_length=255, verbose_name='Follower Name')),
|
||||||
|
('followed_at', models.DateTimeField(verbose_name='Followed At')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cached_followers', to='core.user')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Follower Cache',
|
||||||
|
'verbose_name_plural': 'Followers Cache',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
@ -1,3 +1,120 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
|
||||||
# Create your models here.
|
class User(AbstractUser):
|
||||||
|
pds_url = models.URLField("PDS URL", blank=True, null=True)
|
||||||
|
access_token = models.CharField("Auth Token", max_length=500, blank=True,
|
||||||
|
null=True)
|
||||||
|
refresh_token = models.CharField("Refresh Token", max_length=500,
|
||||||
|
blank=True, null=True)
|
||||||
|
token_expires_at = models.DateTimeField(blank=True, null=True)
|
||||||
|
|
||||||
|
# Agregar related_name para evitar el conflicto
|
||||||
|
groups = models.ManyToManyField(
|
||||||
|
'auth.Group',
|
||||||
|
related_name='custom_user_set',
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
user_permissions = models.ManyToManyField(
|
||||||
|
'auth.Permission',
|
||||||
|
related_name='custom_user_permissions_set',
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.username
|
||||||
|
|
||||||
|
|
||||||
|
class PublicationCache(models.Model):
|
||||||
|
id = models.CharField("Publication ID", max_length=255, primary_key=True)
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE,
|
||||||
|
related_name="cached_publications")
|
||||||
|
content = models.TextField("Content")
|
||||||
|
author = models.CharField("Author", max_length=255)
|
||||||
|
published_at = models.DateTimeField("Published At")
|
||||||
|
is_unread = models.BooleanField("Unread", default=True)
|
||||||
|
|
||||||
|
def mark_as_read(self):
|
||||||
|
self.is_unread = False
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Publication Cache"
|
||||||
|
verbose_name_plural = "Publications Cache"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.author}: {self.content[:20]}..."
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationCache(models.Model):
|
||||||
|
id = models.CharField("Notification ID", max_length=255, primary_key=True)
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE,
|
||||||
|
related_name="cached_notifications")
|
||||||
|
content = models.TextField("Content")
|
||||||
|
type = models.CharField("Type", max_length=50)
|
||||||
|
created_at = models.DateTimeField("Created At")
|
||||||
|
is_unread = models.BooleanField("Unread", default=True)
|
||||||
|
|
||||||
|
def mark_as_read(self):
|
||||||
|
self.is_unread = False
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Notification Cache"
|
||||||
|
verbose_name_plural = "Notifications Cache"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.type}: {self.content[:20]}..."
|
||||||
|
|
||||||
|
|
||||||
|
class FollowerCache(models.Model):
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE,
|
||||||
|
related_name="cached_followers")
|
||||||
|
follower_id = models.CharField("Follower ID", max_length=255)
|
||||||
|
follower_name = models.CharField("Follower Name", max_length=255)
|
||||||
|
followed_at = models.DateTimeField("Followed At")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Follower Cache"
|
||||||
|
verbose_name_plural = "Followers Cache"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.follower_name}"
|
||||||
|
|
||||||
|
|
||||||
|
class FollowingCache(models.Model):
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE,
|
||||||
|
related_name="cached_following")
|
||||||
|
following_id = models.CharField("Following ID", max_length=255)
|
||||||
|
following_name = models.CharField("Following Name", max_length=255)
|
||||||
|
followed_at = models.DateTimeField("Followed At")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Following Cache"
|
||||||
|
verbose_name_plural = "Following Cache"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.following_name}"
|
||||||
|
|
||||||
|
|
||||||
|
class MessageCache(models.Model):
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE,
|
||||||
|
related_name="cached_messages")
|
||||||
|
message_id = models.CharField("Message ID", max_length=255,
|
||||||
|
primary_key=True)
|
||||||
|
sender = models.CharField("Sender", max_length=255)
|
||||||
|
content = models.TextField("Content")
|
||||||
|
sent_at = models.DateTimeField("Sent At")
|
||||||
|
is_unread = models.BooleanField("Unread", default=True)
|
||||||
|
|
||||||
|
def mark_as_read(self):
|
||||||
|
self.is_unread = False
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Message Cache"
|
||||||
|
verbose_name_plural = "Messages Cache"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.sender}: {self.content[:20]}..."
|
||||||
|
Loading…
Reference in New Issue
Block a user