【发布时间】:2021-09-30 05:56:41
【问题描述】:
这是我的模特
from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from django.urls import reverse
class Escort(models.Model):
name = models.CharField(max_length=40)
author = models.ForeignKey(User, on_delete=models.CASCADE)
bio = models.TextField()
phone = models.CharField(max_length=14)
ethnicity = models.CharField(max_length=20)
orientation = models.CharField(max_length=20)
location = models.CharField(max_length=40)
area = models.TextField()
skin_color = models.CharField(max_length=40)
hair_color = models.CharField(max_length=40)
services = models.CharField(max_length=255)
paid = models.BooleanField(default=False)
def __str__(self):
return self.name + '~' + str(self.author)
def get_absolute_url(self):
return reverse('escort-details', args=(str(self.id)))
这些是我的看法
from django.shortcuts import render
from django.views.generic import ListView, DetailView, CreateView
from .models import Escort
#def home(request):
#return render(request, 'home.html',{})
class HomeView(ListView):
model = Escort
template_name = 'home.html'
class EscortDetailView(DetailView):
model = Escort
template_name = 'escort_details.html'
class AddEscortView(CreateView):
model = Escort
template_name = 'add_escort.html'
fields = '__all__'
这些是我的网址
from django.urls import path
from . import views
from .views import HomeView, EscortDetailView, AddEscortView
urlpatterns = [
#path('', views.home, name="home"),
path('', HomeView.as_view(), name="home"),
path('escort/<int:pk>', EscortDetailView.as_view(), name="escort-details"),
path('postad/', AddEscortView.as_view(), name="add-escort"),
]
我还有四个模板用于四个视图
我所做的基本上是创建一个网站来宣传护送服务。我希望用户注册/登录并单击链接“PostAd”并被重定向到带有护送表单的页面。在填写所有护送信息(护送模式)后,用户需要先付款,然后广告/帖子才会出现在主页上(护送的 ul 将在主页中使用 HTML 进行组织)。谁能从这里给我建议?
【问题讨论】:
标签: django django-models django-views django-forms django-templates