Форум сайта python.su
views.py:
from django.shortcuts import render
from django.contrib.auth.models import User
from django.views.generic import DetailView
from register.models import UserCoin
def index2(request):
username = User.objects.all()
usercoin = UserCoin.objects.all()
return render(request, 'main2/index2.html', {"username": username, "usercoin": usercoin})
class Users(DetailView):
model = User
template_name = 'index2.html'
context_object_name = 'user'
class Coins(DetailView):
model = UserCoin
template_name = 'index2.html'
context_object_name = 'coin'
from django.db import models
from django.contrib.auth.models import User
class UserCoin(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
coin = models.DecimalField(null=False, decimal_places=2, max_digits=1000, default=1)
def __str__(self):
return f'{self.coin}'
Офлайн