from django.db import models
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.contrib.contenttypes.models import ContentType
User = get_user_model()
class Servers(models.Model):
name = models.CharField(max_length=255, verbose_name='Все сервера', blank=True, null=True)
id_num = models.PositiveIntegerField(default=0, verbose_name='id-номер')
def __str__(self):
return self.name
class Games(models.Model):
name = models.CharField(max_length=255, verbose_name='Наиминование игры')
id_num = models.PositiveIntegerField(default=0, verbose_name='id-номер')
game_currency = models.CharField(max_length=50, verbose_name='Игровая валюта', blank=True, null=True)
game_account = models.CharField(max_length=50, verbose_name='Аккаунты', blank=True, null=True)
game_items = models.CharField(max_length=50, verbose_name='Предметы', blank=True, null=True)
game_services = models.CharField(max_length=50, verbose_name='Услуги', blank=True, null=True)
sell_currency = models.CharField(max_length=50, verbose_name='Продать игровую валюту', blank=True, null=True)
sell_accounts = models.CharField(max_length=50, verbose_name='Продать аккаунты', blank=True, null=True)
sell_items = models.CharField(max_length=50, verbose_name='Продать предметы', blank=True, null=True)
sell_services = models.CharField(max_length=50, verbose_name='Продать услуги', blank=True, null=True)
server = models.ManyToManyField(Servers, verbose_name='Сервер', blank=True)
image = models.ImageField(verbose_name='Изображение')
price_per = models.CharField(max_length=50, verbose_name='Цена за:', blank=True, null=True)
description = models.TextField(verbose_name='Описание', max_length=500, blank=True, null=True)
def currency_absolute_url(self):
return reverse('games_detail', kwargs={'slug': self.id_num})
def accounts_absolute_url(self):
return reverse('accounts_detail', kwargs={'slug': self.id_num})
def items_absolute_url(self):
return reverse('items_detail', kwargs={'slug': self.id_num})
def services_absolute_url(self):
return reverse('services_detail', kwargs={'slug': self.id_num})
def sell_game_currency_url(self):
return reverse('sell_game_currency', kwargs={'slug': self.id_num})
def __str__(self):
return self.name
class Sell(models.Model):
class Meta:
abstract = True
owner = models.ForeignKey('Customer', null=True, verbose_name='Продавец', on_delete=models.CASCADE)
games = models.ForeignKey(Games, null=True, verbose_name='Игра', on_delete=models.CASCADE)
server = models.ForeignKey(Servers, null=True, verbose_name='Сервер', on_delete=models.CASCADE)
price = models.PositiveIntegerField(default=0, verbose_name='Цена', blank=True, null=True)
def __str__(self):
return f'{self.owner}'
class Availability(Sell):
availability = models.PositiveIntegerField(default=0, verbose_name='Наличие игровой валюты', blank=True, null=True)