Ребят, подскажите, как создать поле author, ссылающееся на пользователя. Я делал так:
from django.db import models
from django.contrib.auth.models import User
class Recipe(models.Model):
author = models.ForeignKey(User)
title = models.CharField(max_length=200)
timestamp = models.DateTimeField(auto_now=True)
text = models.TextField()
def __str__(self):
return self.title
Но когда запускаю миграцию, выдает
ValueError: Lookup failed for model referenced by field recipe.Recipe.author: auth.User
Регистрируюсь вот так:
def register(request):
args = {}
args.update(csrf(request))
args['form'] = UserCreationForm()
if request.POST:
newuser_form = UserCreationForm(request.POST)
if newuser_form.is_valid():
newuser_form.save()
newuser = auth.authenticate(username=newuser_form.cleaned_data['username'], password=newuser_form.cleaned_data['password2'])
auth.login(request, newuser)
return redirect('/')
else:
args['form'] = newuser_form
return render_to_response('register.html', args)