On Tue, Mar 10, 2009 at 16:58, Daniel Roseman
<[email protected]> wrote:
> On Mar 10, 1:14 pm, Dmitry Teslenko <[email protected]> wrote:
>> On Tue, Mar 10, 2009 at 16:06, Daniel Roseman
>> <[email protected]> wrote:
>> > How is the view getting the task_id parameter? Your form is always
>> > posting to edit/, with no parameter, so there's no way it can pass the
>> > task_id to the view. Presumably your URLconf has a default to -1, and
>> > there's no way to get anything else, which is why the form always
>> > inserts.
>> > --
>> > DR.
>>
>> View gets proper task_id; I've added it to the edit.html template and
>> get assured
>> it being set right;
>> Additons go from this link:
>> ===========================================================================
>> ==
>> <a href="/py/test_app/edit">New task</a>
>> ===========================================================================
>> ==
>>
>> And editions go from this link:
>> ===========================================================================
>> ==
>> <a href="/py/test_app/edit/{{ task.pk }}">Edit</a>
>> ===========================================================================
>> ==
>>
>> Here's excerpt from urls.py:
>> ===========================================================================
>> ==
>> (r'^%stest_app/edit/$' % URL_PREFIX,
>> 'test_django.test_app.views.edit' , { 'task_id' : -1 }),
>> (r'^%stest_app/edit/(?P<task_id>\d+)/$' % URL_PREFIX,
>> 'test_django.test_app.views.edit'),
>> ===========================================================================
>> ==
>>
>
> OK, well you'll need to post the form code then.
Here it is:
=============================================================================
from django.forms import ModelForm
class NewTaskForm(ModelForm):
class Meta:
model = Task
exclude = ('is_completed', 'created_date')
=============================================================================
Task defined this way:
=============================================================================
class Task(models.Model):
caption = models.CharField(max_length=255)
importance = models.IntegerField(choices=IMPORTANCE_CHOICES)
probability = models.IntegerField(choices=PROBABILITY_CHOICES)
created_date = models.DateTimeField(default=datetime.datetime.now,
editable = False)
due_date = models.DateTimeField(null=True, blank=True)
is_completed = models.BooleanField(default=False)
def __str__(self):
return self.caption
def get_priority(self):
return self.importance * self.probability
def get_is_overdue(self):
return not self.is_completed and datetime.datetime.now() >
self.due_date
def get_absolute_url(self):
return '/py/test_app/task/%i' % self.pk
=============================================================================
>
> Also you may want to think about whether the view logic is right. I
> can't see anything obvious that would cause your problem, but it's
> needlessly complicated and doesn't catch all cases. For example, what
> happens if the form fails validation? As far as I can see, the user is
> redirected to get_test_app_url() *anyway*, which is clearly wrong -
> you want to redisplay the form with the errors, instead. The Django
> documentation has a good model for edit/update views, I suggest you
> follow that instead.
It's my first django app. I don't aim for production/ I'm skimming
over docs and trying to evaluate django by creating something fast and
dirty.
> Similarly, it's not very Pythonic to pass -1 as the default for when
> there's no task. Why don't you have the view take task_id=None as a
> default parameter, then you don't need to have that default in the
> urls.py.
> --
> DR.
I have severe c++ brain dama..., I mean, background.
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---