У меня здесь проблемы. Вот моя форма:
class PublishBiddingForm(forms.Form):
class Meta:
model = Puja
fields = ("title", "video", "photo", "bidding_end","starting_price")
def save(self, commit=True):
Puja = super(PublishBiddingForm, self).save(commit=False)
if commit:
Puja.save()
return Puja
Вот моя модель:
class Puja(models.Model):
seller = models.OneToOneField(Seller, on_delete=models.CASCADE)
title = models.CharField(max_length=100)
video = models.FileField()
photo = models.ImageField()
published_date = models.DateTimeField("Published: ",default=timezone.now())
bidding_end = models.DateTimeField()
starting_price = models.IntegerField(default=1)
def __str__(self):
return str(self.title)
мой взгляд:
def is_seller(user):
try:
return user.is_authenticated and user.seller is not None
except Seller.DoesNotExist:
return False
@user_passes_test(is_seller)
def publish_bidding(request):
if request.method == "POST":
form = PublishBiddingForm(request.POST)
if form.is_valid():
Puja = form.save()
titulo = form.cleaned_data.get('title')
messages.success(request, f"New bid created: {titulo}")
return redirect("main:homepage")
else:
for msg in form.error_messages:
messages.error(request, f"{msg}: {form.error_messages[msg]}")
return render(request = request,
template_name = "user_templates/register.html",
context={"form":form})
form = PublishBiddingForm
return render(request = request,
template_name = "publish_bidding.html",
context={"form":form})
и ошибка:
Кто-нибудь знает, что происходит? У меня успешно реализована форма регистрации, и я использовал ее в качестве модели для ее создания, но я получаю только ошибки. Любая помощь будет высоко ценится.
Редактировать 1: Вот мой urls.py:
from django.urls import path
from . import views
app_name= "main"
urlpatterns = [
path("", views.homepage, name="homepage"),
path("logout", views.logout_request, name="logout"),
path("login", views.login_request, name="login"),
path("register/", views.register, name="register"),
path("account/", views.account, name="account"),
path("publish_bidding/", views.publish_bidding, name="publish_bidding"),
]