У меня есть шаблон, в который я передаю все проекты, и я oop через них и создаю таблицу, которая показывает, сколько задач связано с каждым проектом. Затем у меня есть кнопка с надписью «Создать новое задание для.
». Однако теперь я не могу попасть на свою домашнюю страницу из-за ошибки:
Reverse for 'createTask' with no arguments not found. 1 pattern(s) tried: ['(?P<projID>[^/]+)/newtask/$']
Но я могу напрямую go to / projects и просмотрите шаблон проектов. Но при нажатии на кнопку я получаю ту же ошибку за исключением фактического projID в URL. Есть идеи, что я делаю неправильно?
Модели:
name = models.CharField(max_length=30, unique=True, primary_key=True)
#task_id = models.CharField(max_length=30, unique=True, primary_key=True)
description = models.CharField(max_length=255)
date_created = models.DateTimeField(auto_now_add=True)
#createdBy = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
#project = models.ForeignKey('Project', on_delete=models.CASCADE, related_name='tasks')
# do you want to create a task without a project!?!?!?!?
project = models.ForeignKey('Project', on_delete=models.CASCADE, null=True)
owner = models.ForeignKey(Account, on_delete=models.CASCADE, related_name='taskowner', null=False)
user = models.ForeignKey(Account, on_delete=models.CASCADE, related_name='profile', null=True)
team = models.ForeignKey(Team, on_delete=models.CASCADE, related_name='teams', null=True)
#private = models.ForeignKey('Project', on_delete=models.CASCADE, related_name='privatetask', default=False)
# open or closed
OPEN = 'open'
CLOSED = 'closed'
INPROCESS = 'inprocess'
STATUS = [
(OPEN, 'Open Task'),
(CLOSED, 'Closed Task'),
(INPROCESS, 'In Process'),
]
status = models.CharField(max_length=9, choices=STATUS, default=OPEN)
def __str__(self):
return self.name
def is_private(self):
return self.private
def owner(self):
return self.owner
class Project(models.Model):
name = models.CharField(max_length=30, unique=True, primary_key=True)
#project_id = models.CharField(max_length=30, unique=True, primary_key=True)
description = models.CharField(max_length=255)
date_created = models.DateTimeField(auto_now_add=True, null=True)
private = models.BooleanField(default=False)
owner = models.ForeignKey(Account, on_delete=models.CASCADE, related_name='projectowner')
#tasks = models.ManyToManyField(Task)
#dateCreated2 = models.DateTimeField(auto_now_add=True)
#teams = models.ManyToManyField(Team)
#individualContributers = models.ForeignKey(Users, on_delete=models.CASCADE, null=True)
#starter = models.ForeignKey(User, on_delete=models.CASCADE, related_name='projects')
def __str__(self):
return self.name
def is_private(self):
return self.private
def owner(self):
return self.owner
def get_task_count(self):
return Task.objects.filter(project=self.name).count()
Вид:
def create_task(request, projID):
projectName = projID
if request.method == "POST":
#projectName = projID
form = CreateTaskForm(request.POST)
if form.is_valid():
task = form.save(commit=False)
#task.project = projectName
task.project = Project.objects.get(name=projectName)
task.save()
return render(request, 'about.html')
else:
form = CreateTaskForm()
return render(request, 'home.html')
URL
path('<str:projID>/newtask/', views.create_task, name='createTask'),
HTML
{% for p in projects %}
<tr>
<td>
<a href="{% url 'projRequested' projID=p.name %}"><h3>{{ p.name }}</h3></a>
<small class="text-muted d-block">{{ p.description }}</small>
</td>
<td class="align-middle">
<small>{{ p.get_task_count }}</small>
</td>
<td class="align-middle">
<a class="btn btn-primary" href="{% url 'createTask' projID=p.name %}" role="button">Create Task for {{ p.name }}</a>
</td>
</tr>
{% endfor %}
Форма:
class CreateTaskForm(forms.ModelForm):
name = forms.CharField(label='Task Name')
description = forms.CharField(label='Description', widget=forms.Textarea)
class Meta:
model = Task
fields = ['name', 'description', 'project',]
def clean_name(self):
name = self.cleaned_data.get('name')
qs = Task.objects.filter(name=name)
if qs.exists():
raise forms.ValidationError('Task Already Exists')
return name