Я учусь Django 2.2, я пытаюсь создать модель из базы sKills на основе родительской модели с именем Profile:
Но у меня есть эта ошибка:
DoesNotExist at /skills/
Profile matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8080/skills/
Django Version: 2.2
Exception Type: DoesNotExist
Exception Value:
Profile matching query does not exist.
in Навыки => models.py:
from django.db import models
from profiles.models import Profile
from django.core.validators import MaxValueValidator, MinValueValidator
# Create your models here.
class Skill(models.Model):
user = models.ForeignKey(Profile, on_delete=models.CASCADE)
name = models.CharField(max_length=220)
score = models.PositiveIntegerField(
validators=[MinValueValidator(1), MaxValueValidator(5)])
def __str__(self):
return "{}-{}-{}".format(self.user, self.name, self.score)
в Навыки => Views.py:
# Create your views here.
def skill_view(request):
user_id = request.user.id
profile = Profile.objects.get(pk=user_id)
#profile = get_object_or_404(Profile, pk=user_id)
SkillFormset = inlineformset_factory(Profile, Skill,fields='__all__',extra=1)
formset = SkillFormset( instance=profile)
context = {
'formset': formset
}
return render(request,'skills/add.html',context)
Навыки => urls.py:
app_name = 'skills'
urlpatterns = [
path('', skill_view, name='my-skills'),
]
В Навыки => шаблоны => навыки => добавить. html:
{% extends 'base.html' %}
{% block title %}my skills{% endblock title %}
{% block content %}
<form action="" method="POST">
{{formset}}
</form>
{% endblock content %}
В профиле => Модели:
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import FileExtensionValidator
# Create your models here.
class Profile(models.Model):
name = models.ForeignKey(User, on_delete=models.CASCADE)
website = models.URLField(blank=True)
avatar = models.ImageField(upload_to='uploads/img', validators=[FileExtensionValidator(allowed_extensions=['png'])], blank=True)
updated = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)
@property
def get_created(self):
return self.created.strftime("%m/%d/%Y, %H:%M:%S")
def __str__(self):
return "{}-{}".format(self.name, self.get_created)
У меня есть профиль пользователя в базе данных я не понимаю :
Спасибо за помощь