check column value and manipulate css djangotables2 - django

I am using djangotables2 for the first time. I have successfully displayed a table which
is a list of dictonaries,where key and values are calculated from various sources in my
project database.
I have a requirement where i have to check the value of a column and change the background color like css or apply bootstrap badges.
Sample code :-
views.py
data_list = []
#search
query = request.GET.get('q')
if query:
user_list = UserProfile.objects.filter(user__email__icontains=query)
else:
user_list = UserProfile.objects.order_by("-user__date_joined")
for userprofile in user_list:
data_list.append({'user_id': userprofile.id,
'first_name': userprofile.user.first_name,
'last_name': userprofile.user.last_name,
'address': get_city(userprofile),
'dateofbirth': userprofile.dateofbirth,
'anniversary': "NA",
'number_of_orders':
get_total_orders(userprofile),
'total_revenue': get_total_revenue(userprofile),
'highest_order': get_higest_order(userprofile),
'registration_date':
userprofile.user.date_joined.date().strftime("%B %d %Y"),
'last_order_date': get_last_order(userprofile),
'last_order_to_present_day_differene':
get_difference_from_last_order(userprofile)
})
data = ThemedCRMTable(data_list, prefix="3-")
RequestConfig(request, paginate={"per_page": 15}).configure(data)
tables.py
class CRMTable(tables.Table):
user_id = tables.Column()
first_name = tables.Column()
last_name = tables.Column()
address = tables.Column()
dateofbirth = tables.Column()
anniversary = tables.Column()
number_of_orders = tables.Column()
total_revenue = tables.Column()
highest_order = tables.Column()
registration_date = tables.Column()
last_order_date = tables.Column()
last_order_to_present_day_differene = tables.Column()
class ThemedCRMTable(CRMTable):
class Meta:
attrs = {'class': 'paleblue'}
template
{% load static %}
{% load render_table from django_tables2 %}
<!doctype html>
<html>
<head>
<title>CRM Report</title>
<link rel="stylesheet" href="/static/report/css/screen.css" />
<link href="{% static 'css/bootstrap.css' %}" rel="stylesheet">
<script src="{% static 'js/jquery.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
</head>
<body>
<div class="container">
<div class="row" style="margin-top:2%;text-align:center;">
<form class="form-search pull-left">
<div class="input-append">
<input type="text" class="span4 search-query" name="q">
<button type="submit" class="btn">Search</button>
</div>
</form>
<strong style="font-size:20px;">CRM Report</strong>
<a class="btn btn-inverse pull-right offset1" href="/">
<span><i class="icon-step-backward icon-white icon-alignment"></i></span>
Go Back
</a>
<a class="btn btn-success pull-right offset1" href="{% url generate_crm_report_csv %}">
<span><i class="icon-download icon-white icon-alignment"></i></span>
CRM Report
</a>
</div>
{% render_table data_list %}
</div>
</body>
</html>
Question:-
I want to make the cell background red where the value of last column last_order_to_present_day_differene is greator than 30

Related

Page not found(404) : No category matches the given query

Below is my error
Page not found(404)
No category matches the given query.
request method: GET
Request URL: http://127.0.0.1:8000/store/slug/
Raised by: store.views.product_in_category
Using the URLconf defined in rhizomeedu_prj.urls, Django tried these URL patterns, in this order:
admin/
noticeboard/
markdownx/
store/ [name='product_all']
store/ <slug:category_slug>/ [name='product_in_category']
The current path, store/slug/, matched the last one.
And this is the model of Category.
class Category(models.Model):
name = models.CharField(max_length=200, db_index=True)
meta_description = models.TextField(blank=True)
slug = models.SlugField(max_length=200, db_index=True, unique=True, allow_unicode=True)
class Meta:
ordering = ['name']
verbose_name = 'category'
verbose_name_plural = 'categories'
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('store:product_in_category', args={"slug":self.slug})
Related part of views.py
def product_in_category(request, category_slug=None):
current_category = None
categories = Category.objects.all()
products = Product.objects.filter(available_display=True)
if category_slug:
current_category = get_object_or_404(Category, slug=category_slug)
products = products.filter(category=current_category)
return render(request, 'store/product_list.html',
{'current_category': current_category, 'categories': categories, 'products': products})
And this is whole urls.py
from django.urls import path, include
from .views import *
app_name = 'store'
urlpatterns = [
path('', product_in_category, name="product_all"),
path('<slug:category_slug>/', product_in_category, name="product_in_category"),
path('<int:id>/<product_slug>/', ProductDetail.product_detail, name="product_detail"),
path('create_product/', ProductCreate.as_view()),
path('cart/', detail, name='detail'),
path('add/<int:product_id>/', add, name='item_add'),
path('remove/<int:product_id>/', remove, name='item_remove'),
path('orders/create/', order_create, name='order_create'),
path('orders/create_ajax/', OrderCreateAjaxView.as_view(), name='order_create_ajax'),
path('orders/checkout/', OrderCheckoutAjaxView.as_view(), name='order_checkout'),
path('orders/validation/', OrderImpAjaxView.as_view(), name='order_validation'),
path('orders/complete/', order_complete, name='order_complete'),
path('admin/order/<int:order_id>/', admin_order_detail, name='admin_order_detail'),
path('admin/order/<int:order_id>/pdf/', admin_order_pdf, name='admin_order_pdf'),
path('cart/', detail, name='detail'),
path('cart/add/<int:product_id>/', add, name='product_add'),
path('cart/remove/<int:product_id>/', remove, name='product_remove'),
]
Lastly, this is related part of the template product_list.html
<div class="py-3">
<ul class="nav nav-tabs justify-content-center">
<li class="nav-item">
<a class="nav-link {% if not current_category %}active{% endif %}" href="/store/">전체</a>
</li>
{% for c in categories %}
<li class="nav-item">
<a class="nav-link {% if current_category.slug == c.slug %}active{% endif %}" href="{{c.get_absolute_url}}" style="color:black">{{c.name}}</a>
</li>
{% endfor %}
</ul>
</div>
<!-- Section-->
<section class="py-5">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
{% for p in products %}
<div class="col mb-5">
<div class="card h-100">
<!-- Product image-->
<img class="card-img-top" src="https://dummyimage.com/450x300/dee2e6/6c757d.jpg" alt="..." style="opacity:0.7"/>
<!-- Product details-->
<div class="card-body p-4">
<div class="text-center">
<!-- Product name-->
<h5 class="fw-bolder">{{p.title}}</h5>
<!-- Product price-->
₩{{p.price}}
</div>
</div>
<!-- Product actions-->
<div class="card-footer p-4 pt-0 border-top-0 bg-transparent">
<div class="text-center"><a class="btn btn-outline-dark mt-auto my-1" href="{{ p.get_absolute_url }}">detail</a><a class="btn btn-outline-dark mt-auto my-1" href="#">add to cart</a></div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
</main>
<!-- Bootstrap core JS-->
{% include 'single_pages/footer.html' %}
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core theme JS-->
<script src="{% static 'js/scripts.js' %}"></script>
{% endblock %}
Every time I click category other than 'All',
it raises error mentioned before.
Also the url turns '127.0.0.1:8000/store/slug'
which is bizzare because there's no category named 'slug'.
What's wrong with my code?
Help me.
I guess this is wrong:
def get_absolute_url(self):
return reverse('store:product_in_category', args={"slug":self.slug})
and needs to be changed to:
def get_absolute_url(self):
return reverse('store:product_in_category', args={"category_slug":self.slug})
Check this by changing get_absolute_url,
def get_absolute_url(self):
return reverse("store:product_in_category", args=[str(self.slug)])
and the reason for 404 page not found error might be because there's no category object with category_slug you are passing and it shows error in this line,
current_category = get_object_or_404(Category, slug=category_slug)
According to the official document of Django, this problem has caused by violating rules related with url and slug.
When you want to put slug into url in a form of slug(not string), it has to be only composed of ASCII components.
My slug was not, so problem solved when I changed it.

Django-ckeditor showing content as textarea

I'm working with django ckeditor now and I can't display content that can be saved normally and is displayed in the admin panel. Content is always displayed as textarea
As you can see at the image, editor is working properly, also if i go to admin panel everything is OK, but if i want to display content of "body" ({{ form.body|safe}}), it will display only textarea of HTML code.
models.py
class Stage(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
game_id = models.ForeignKey(Game,
on_delete=models.CASCADE)
name = models.CharField(max_length=128)
sequence = models.IntegerField(null=False)
body = RichTextUploadingField(config_name='LeftFields', blank=True, null=True)
def get_questions(self):
return Question.objects.filter(stage_id = self.id)
def __str__(self):
return str(self.name)
forms.py
class StageForm(ModelForm):
class Meta:
model = Stage
fields = ['body','name']
widgets = {
'name': TextInput(attrs={
'class': "left_input",
'style': "width: 69.3%;",
}),
}
views.py
#login_required(login_url='/signin')
#user_passes_test(lambda u: u.is_staff)
def edit(request, gameid,id):
stage = Stage.objects.get(pk=id)
if request.method == 'POST':
form = StageForm(request.POST, instance=stage)
if form.is_valid():
form.save()
return redirect('/edit/' + gameid + '/' + id)
form = StageForm(instance=stage)
return render(request, "homeSuperuser/edit_stage.html", {'stage': stage, 'form': form,'gameid':gameid})
edit_stage.html
<!doctype html>
<html>
<head> {% load static %}
<link rel="stylesheet" href="{% static 'css/edit_pages.css' %}" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script type="text/javascript" src="{% static 'js/edit.js' %}"></script>
</head>
<body>
<div class="row" id="mainDIV">
<form id="main" method="post" action="{{ request.path }}">
{% csrf_token %}
<div class="divs">
<a>Název: </a>
{{ form.name}}
</div>
<div class="divs"><a>Kontent:</a>
{{ form.media }}
{{ form.body}}
</div>
<div class="div_cent"><input type="submit" value="Uložit" class="subm" /></div>
</form>
</div>
{{ form.body|safe}}
</body>
</html>
form.body is the field itself, so includes the HTML textarea markup.
Instead of
{{ form.body|safe}}
try
{{ form.body.value|safe}}

Django with bootstrap DateTimePicker: inputElement.dataset is undefined

When I try to add options to dateTimePicker it stops working. Website raise "Something went wrong! Check browser console for errors. This message is only visible when DEBUG=True", and when I enter the console on the browser I see this:
Uncaught TypeError: inputElement.dataset is undefined
and the error picks up from https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css
in the datapicker-widget.js file
class Topic(models.Model):
speaker = models.ForeignKey(Profile, on_delete=models.SET(GUEST_ID))
seminar = models.ForeignKey(Seminar, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
description = models.TextField(default='')
speaker_name = models.CharField(max_length=200, default='')
date = models.DateTimeField(null=True, blank=True)
def __str__(self):
return self.title
class TopicCreateView(LoginRequiredMixin, CreateView):
model = Topic
form_class = TopicPageForm
template_name = 'seminar/topic_form.html'
def get_initial(self, *args, **kwargs):
initial = super(TopicCreateView, self).get_initial(**kwargs)
initial = initial.copy()
initial['speaker'] = self.request.user.profile
initial['speaker_name'] = self.request.user
initial['date'] = datetime.datetime.now()
return initial
...
`
{% extends "seminar/base.html" %}
{% load django_bootstrap5 %}
{% load crispy_forms_tags %}
{% block head_content %}
{% endblock %}
{% block content %}
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Topic</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Save</button>
</div>
</form>
</div>
{% endblock content %}
head
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" type='text/css' href="{% static 'users/style.css' %}">
<link rel="stylesheet" type='text/css' href="{% static 'seminar/main.css' %}">
bottom body
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
{{ form.media }}
As long as it doesn't add defaultDate in the options it doesn't display the error. The same is true if I want to add autoclose and many other options. (what type i should use in attrs?)
class TopicPageForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(TopicPageForm, self).__init__(*args, **kwargs)
class Meta:
model = Topic
fields = ['speaker', 'title', 'description', 'date', 'speaker_name']
template_name = 'seminar/topic_form.html'
widgets = {
'date': DateTimePickerInput(
attrs={'class': 'form-control input-sm', 'type': 'dataTime'},
options={
"format": "YYYY/MM/DD HH/mm", # moment date-time format
'defaultDate': True,
},
)
}
How to use other options?

Django Updateview html templet with links using current instance object values

I have two models
class AccGroup(models.Model):
grpid = models.BigAutoField(primary_key=True, editable=False)
groupname = models.CharField(max_length=40, default="")
class Meta:
indexes = [models.Index(fields=['groupname'])]
def __str__(self):
return "%s" % (self.groupname)
class Account(models.Model):
accid = models.BigAutoField(primary_key=True, editable=False)
shortcut = models.CharField(max_length=10, default="")
accname = models.CharField(max_length=100, default="")
accgrp = models.ForeignKey(AccGroup, on_delete=models.RESTRICT, default=0)
class Meta:
indexes = [models.Index(fields=['shortcut']),models.Index(fields=['accname'])
]
def __str__(self):
return "%s--%s" % (self.shortcut, self.accname)
One Update View defined on above model
class AccountUpdateForm(UpdateView):
model = Account
fields = ['shortcut','accname','accgrp']
def get_success_url(self):
currid = self.kwargs['pk']
account = Account.objects.get(pk=currid)
print(account)
return ('/polls/accmst/'+ str(account.accid))
and the corresponding HTML templet
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Update Account</title>
</head>
<body>
<form action="" method="post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Save" />
</form>
<p>
<a class="btn btn-info btn-sm" href="{% url 'polls:accgrpList' %}">Back To Group List</a>
</p>
<p>
<a class="btn btn-info btn-sm" href="{% url 'polls:accgrpList' form.accgrp.grpid %}">Back To Account List</a>
</p>
</body>
</html>
so on success the same page is displayed using the current account object primary key
there are two more links
Link 1 point the a group list <polls:accgrpList> which translates to http://localhost:8000/polls/accgrplist
Link 2 my problem is I want to point to url
http://localhost:8000/polls/accgrplist/2
where the last part is the grpid of the current account object
following change in my templet did my job
<a class="btn btn-info btn-sm" href="{% url 'polls:accgrpList' form.accgrp.value %}">Back To Account List</a>

Django cannot get dialog box to display relevant information

I have two forms that I am using on one (html page below) page. One form (create_task_form) create's tasks, and the other (edit_task_form) should edit/show tasks. To make things more difficult on myself I decided to display the tasks in a list, and when a user clicks on a task, it should display a form with the task details in a dialog box. Again, the create dialog box works as should, however I cannot figure out how to populate the (edit_task_form) edit/show form for a existing task from a list in a dialog box with the relevent task info.
Views.py: Edited
def status(request, project_id, task_id=None):
need_owner_list = Task.objects.filter(project__id=project_id, status=0)
in_progresss_list = Task.objects.filter(project__id=project_id, status=1)
pending_review_list = Task.objects.filter(project__id=project_id, status=2)
t = get_object_or_404(Task, pk=task_id)
p = get_object_or_404(Project, pk=project_id)
if project_id:
p = get_object_or_404(Project, pk=project_id)
else:
p = None
# if task_id:
# t = get_object_or_404(Task, pk=task_id)
# else:
# t = None
if request.method == 'POST':
p = get_object_or_404(Project, pk=project_id)
post_task = PostTaskForm(request.POST)
if post_task.is_valid():
task = post_task.save(commit=False)
task.project = p
task.save()
url = reverse('status', args=[project_id])
return HttpResponseRedirect(url)
else:
post_task = PostTaskForm()
if request.method == 'POST':
t = get_object_or_404(Task, pk=task_id)
tform = PostTaskForm(request.POST, instance = t)
if form.is_valid():
task = tform.save()
url = reverse('status', args=[project_id])
return HttpResponseRedirect(url)
else:
tform = PostTaskForm(instance=t)
c = Context({
'need_owner_list': need_owner_list,
'in_progresss_list': in_progresss_list,
'pending_review_list': pending_review_list,
'project': p,
'request': request,
'pform': post_task,
'task_id': task_id,
'project_id': project_id,
'task': t,
'tform': tform,
})
return render_to_response('project/status.html', c, context_instance=RequestContext(request))
HTML Page
{% extends "base.html" %}
{% block title %} project status {% endblock %}
{%block content %}
<body>
<head>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/status.css"/>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/create_task.css"/>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/status_box.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/list_items.css">
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/ownerless_task_list.css">
<!-- These are the scripts for the drag and drop functionality. -->
<script language="JavaScript" type="text/javascript" src="{{ STATIC_URL }}javascript/jquery.sortable.js"></script>
</head>
<div id=lists_box>
{% if need_owner_list %}
<ul id="needs_owner" class="connected list">
{% for task in need_owner_list|slice:":20" %}
<li class="row1"><a href="#divModalDialog1" >{{ task.title }} {% url task task.id%}</a></li>
{% endfor %}
</ul>
<div id="divModalDialog1" class="divModalDialog" type="hidden">
<div id=task_div>
X
<form id="edit_task_form" action="{{ task }}" value="{{ task }}" method="POST">
<input type="hidden" name="task" value="{{ task }}"/>
{% csrf_token %}
{{ pform }}
<input type="SubmitEdit" value="Submit Edit" onclick="self.close()">
<input type="Reset" value="Reset">
</form>
</div>
</div>
{% else %}
<ul id="needs_owner" class="connected list">
<li class="row1">No tasks are available.</li>
</ul>
{% endif %}
{% if in_progresss_list %}
<ul id="in_progress" class="connected list">
{% for task in in_progresss_list|slice:":20" %}
<li class="row1">{{ task.title }}</li>
{% endfor %}
</ul>
{% else %}
<ul id="in_progress" class="connected list">
<li class="row1">No tasks are available.</li>
</ul>
{% endif %}
{% if pending_review_list %}
<ul id="pending_status" class="connected list">
{% for task in pending_review_list|slice:":20" %}
<li class="row1">{{ task.title }}</li>
{% endfor %}
</ul>
{% else %}
<ul id="pending_status" class="connected list">
<li class="row1">No tasks are available.</li>
</ul>
{% endif %}
</div>
<!-- START:This section below is deals with the submit task popup window -->
{% if user.is_authenticated %}
<script>
$(function() {
$('.sortable').sortable();
$('.handles').sortable({
handle: 'span'
});
$('.connected').sortable({
connectWith: '.connected'
});
$('.exclude').sortable({
items: ':not(.disabled)'
});
});
</script>
<!-- The JS is added here to load after login. If this is added the the top of the page it conflicts with login_link.js -->
<script src="{{ STATIC_URL }}javascript/create_task.js" type="text/javascript"></script>
<a id="submit_task">submit task</a>
<div id="task_popout">
<a id="task_popoutClose">X</a>
{% if form.has_errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<form id="create_task_form" action="" value="submit_task" method="POST">
<input type="hidden" name="project" value="{{ project_id }}"/>
{% csrf_token %}
{{ pform }}
<input type="Submit" value="Submit Task" onclick="self.close()">
<input type="Reset" value="Reset">
</form>
</div>
<div id="taskbackgroundPopup"></div>
{% else %}
<p id="login_message">Please <a style="color:blue;" href="#authenticate" id="task_chat">log in</a> to submit/edit tasks or particapate in chats.</p>
{% endif %}
<div id="ticket_stats">
<div id="owner_label" class="text">Owner:</div>
<div id="owner" class="text">{{project.owner|safe}}</div>
<div id="tags_label" class="text">Tags:</div>
<div id="tags" class="text">{{project.tags|safe}}</div>
<div id="created_label" class="text">Created:</div>
<div id="created_date" class="text">{{project.date_created|date:"d/m/Y"}}</div>
<div id="updated_label" class="text">Updated:</div>
<div id="last_updated" class="text">{{project.date_updated|date:"d/m/Y"}}</div>
</div>
</body>
{%endblock%}
models.py
class Project(models.Model):
title = models.CharField(max_length=50, verbose_name='')
slug = models.SlugField(max_length=50, editable=False)
owner = models.ForeignKey(User, editable=False)
problem = tinymce_models.HTMLField(verbose_name='')
date_created = models.DateTimeField(editable=False)
date_updated = models.DateTimeField(editable=False)
tags = TagField(verbose_name='')
def set_tags(self, tags):
Tag.objects.update_tags(self, tags)
def __unicode__(self):
return self.tags
def __unicode__(self):
return self.id
def __unicode__(self):
return self.title
#This overrides the save function in the project/views.py module. It checks the
#created date against the updated date, and updates the updated date if needed.
#Also this takes the title and slugifies it so it can be rendered in the URL.
def save(self, *args, **kwargs):
if not self.id:
self.date_created = datetime.now()
self.date_updated = datetime.now()
self.slug = slugify(self.title)
super(Project, self).save(*args, **kwargs)
class PostProjectForm(ModelForm):
class Meta:
model = Project
STATUS_CHOICES = (
('0', 'Needs Owner'),
('1', 'In Progress'),
('2', 'Comp/Pend/Review'),
('3', 'Complete')
)
class Task(models.Model):
title = models.CharField(max_length=50)
project = models.ForeignKey(Project, editable=False)
assignee = models.ForeignKey(User, null=True, blank=True)
task_desc = models.TextField()
solution = models.TextField(blank=True)
status = models.CharField(max_length=1, default='0', choices=STATUS_CHOICES)
date_created = models.DateTimeField(editable=False)
date_updated = models.DateTimeField(editable=False)
def save(self, *args, **kwargs):
if not self.id:
self.date_created = datetime.now()
self.date_updated = datetime.now()
super(Task, self).save(*args, **kwargs)
def __unicode__(self):
return self.id
def __unicode__(self):
return "%s" % self.object_pk
class PostTaskForm(ModelForm):
class Meta:
model = Task
URLs.py
url(r'^status/(?P<idea_id>\d+)$', 'status', name='status'),
url(r'^status/(?P<idea_id>\d+)/(?P<task_id>\d+)$', 'status', name='status_task'),
TL;DR
How can I get a the edit_task_form to display the relevant data from Tasks so that a user can edit/view a task?
Thanks in advance!
not sure but, you have...
if request.method == 'POST':
p = get_object_or_404(Project, pk=project_id)
post_task = PostTaskForm(request.POST)
...
else:
post_task = PostTaskForm()
^ so from the above it looks like it might not populate the form if you are making the dialog with a javascript GET request (?)