You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.8 KiB
138 lines
3.8 KiB
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
from dj_language.field import LanguageField
|
|
from django.core.validators import RegexValidator
|
|
|
|
|
|
class Comment(models.Model):
|
|
"""
|
|
Comment model that stores user information directly
|
|
"""
|
|
# User information
|
|
user_avatar = models.ImageField(
|
|
upload_to='comments/avatars/%Y/%m/',
|
|
null=True,
|
|
blank=True,
|
|
verbose_name=_('User Avatar')
|
|
)
|
|
user_fullname = models.CharField(
|
|
max_length=255,
|
|
verbose_name=_('User Full Name'),
|
|
help_text=_('Full name of the user who made the comment')
|
|
)
|
|
user_slogan = models.CharField(
|
|
max_length=500,
|
|
null=True,
|
|
blank=True,
|
|
verbose_name=_('User Slogan'),
|
|
help_text=_('User slogan or bio')
|
|
)
|
|
|
|
# Comment content
|
|
comment_text = models.TextField(
|
|
verbose_name=_('Comment Text'),
|
|
help_text=_('The actual comment content')
|
|
)
|
|
language = LanguageField(null=True)
|
|
# Ordering and timestamps
|
|
order = models.PositiveIntegerField(
|
|
default=0,
|
|
verbose_name=_('Order'),
|
|
help_text=_('Order for sorting comments')
|
|
)
|
|
created_at = models.DateTimeField(
|
|
auto_now_add=True,
|
|
verbose_name=_('Created At')
|
|
)
|
|
|
|
class Meta:
|
|
ordering = ['order', '-created_at']
|
|
verbose_name = _('Comment')
|
|
verbose_name_plural = _('Comments')
|
|
|
|
def __str__(self):
|
|
return f"{self.user_fullname}: {self.comment_text[:50]}..."
|
|
|
|
|
|
class AppVersion(models.Model):
|
|
"""
|
|
Model for storing app versions with APK files and descriptions
|
|
"""
|
|
class AppType(models.TextChoices):
|
|
GOOGLE_PLAY = 'google_play', _('Google Play')
|
|
APP_STORE = 'app_store', _('App Store')
|
|
version = models.CharField(
|
|
max_length=20,
|
|
unique=True,
|
|
validators=[
|
|
RegexValidator(
|
|
regex=r'^\d+\.\d+\.\d+$',
|
|
message='Version must be in format X.Y.Z (e.g., 1.0.0)'
|
|
)
|
|
],
|
|
verbose_name=_('Version'),
|
|
help_text=_('Application version in format X.Y.Z (e.g., 1.0.0)')
|
|
)
|
|
|
|
apk_file = models.FileField(
|
|
upload_to='app_versions/',
|
|
verbose_name=_('APK File'),
|
|
help_text=_('Application APK file')
|
|
)
|
|
|
|
description = models.TextField(
|
|
verbose_name=_('Description'),
|
|
help_text=_('Release notes and changes for this version'),
|
|
blank=True
|
|
)
|
|
|
|
app_type = models.CharField(
|
|
max_length=20,
|
|
choices=AppType.choices,
|
|
default=AppType.GOOGLE_PLAY,
|
|
verbose_name=_('App Type'),
|
|
help_text=_('App distribution platform')
|
|
)
|
|
|
|
app_store_downloads = models.PositiveBigIntegerField(
|
|
default=0,
|
|
verbose_name=_('App Store Downloads'),
|
|
help_text=_('Total number of downloads on Apple App Store')
|
|
)
|
|
|
|
google_play_downloads = models.PositiveBigIntegerField(
|
|
default=0,
|
|
verbose_name=_('Google Play Downloads'),
|
|
help_text=_('Total number of downloads on Google Play')
|
|
)
|
|
|
|
is_active = models.BooleanField(
|
|
default=True,
|
|
verbose_name=_('Active'),
|
|
help_text=_('Is this version active?')
|
|
)
|
|
|
|
created_at = models.DateTimeField(
|
|
auto_now_add=True,
|
|
verbose_name=_('Created At')
|
|
)
|
|
|
|
updated_at = models.DateTimeField(
|
|
auto_now=True,
|
|
verbose_name=_('Updated At')
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = _('App Version')
|
|
verbose_name_plural = _('App Versions')
|
|
ordering = ['-created_at']
|
|
|
|
def __str__(self):
|
|
return f'Version {self.version}'
|
|
|
|
@classmethod
|
|
def get_latest_active(cls):
|
|
"""
|
|
Get the latest active version
|
|
"""
|
|
return cls.objects.filter(is_active=True).order_by('-created_at').first()
|