thank you, Shawn, for posting your working and tested example. It
answered my questions (basically the same as the original post on this
thread) and got my head clear.
I agree in general with the point that the Django docs are not really
complete on this issue; I'd like it if the Forms/ModelForm
What I'm doing now is
# TEMPLATE
{% if modelform.instance.id %}
{% endif %}
# The POST part of the view method
pk = request.POST.get('pk',None)
if pk:
model = models.House.objects.get(pk=pk)
modelform = forms.MyModelForm(request.POST, instance=house)
else:
modelform = forms.MyModelFo
This is an excellent thread. I came here with the same questions as
Marc. My revelation seems to be that forms are for data, and saving
is control. And these two have separate concerns/goals. Such that
fields shouldn't be in forms for the sole reason to make control of
the form function proper
To expand on what Dan said with a full (tested and working) example:
In urls.py:
(r'^partner/$', 'partner_page'),
(r'^partner/(?P\d+)/$', 'partner_page'),
In the form tag of your template:
The view:
@login_required
def partner_page(request, partner_id = None):
if par
Oh I gotcha now.
Django model forms by default do not represent auto fields (ID's)
because it wouldn't make much sense for a user to be able to edit the
PK in a form. Having said that, I do understand why you need to be
able to see the PK.
I shown in my example, I personally prefer to represent
Of course! The mistake is that I didn't have the ID in the URL, but I
took the partner to be edited somewhere from the session. I'll change
the code and it should work as expected.
Thanks again for your patience
Marc
On Jul 21, 10:57 pm, Daniel Roseman wrote:
> On Jul 21, 9:34 pm, mettwoch wr
On Jul 21, 9:34 pm, mettwoch wrote:
> I'd like this to work:
>
> class PartnerForm(forms.ModelForm):
> class Meta:
> model = Partner # I expect that all fields are included in
> the form (the 'id' field as well)
>
> def partner_new(request):
> form = PartnerForm()
> return r
I'd like this to work:
class PartnerForm(forms.ModelForm):
class Meta:
model = Partner # I expect that all fields are included in
the form (the 'id' field as well)
def partner_new(request):
form = PartnerForm()
return render_to_response('pos.html', {'form': form},
RequestCo
On Jul 21, 2009, at 4:22 PM, Dan Harris wrote:
>
> What do you mean by having the ID "in" the form? I don't quite
> understand what you are trying to do.
>
> On Jul 21, 4:15 pm, mettwoch wrote:
>> Ok, I come back to what I wrote before. If the partner already exists
>> it has an id (primary-key
What do you mean by having the ID "in" the form? I don't quite
understand what you are trying to do.
On Jul 21, 4:15 pm, mettwoch wrote:
> Ok, I come back to what I wrote before. If the partner already exists
> it has an id (primary-key or whatever). If it doesn't exist it has no
> id. I'd just
Ok, I come back to what I wrote before. If the partner already exists
it has an id (primary-key or whatever). If it doesn't exist it has no
id. I'd just like to have the id in the form. Is it a bug, is
something missing here or am I completely on the wrong track. That's
basic database form handlin
This may not be helpful but here is how I usually go about processing
model forms:
class Partner(models.Model):
# this is your model, DB fields go in here
# This is your model form
class PartnerForm(forms.ModelForm):
class Meta:
model = Partner
# This is the view that displays a ne
On Jul 21, 2009, at 3:39 PM, mettwoch wrote:
>
> Sorry to insist, but that's what I don't understand here. How can I
> know that the partner that is 'posted' is new or not? I really become
> crazy here. I can't believe after all the good things I've discovered
> in Django that this can be so har
Sorry to insist, but that's what I don't understand here. How can I
know that the partner that is 'posted' is new or not? I really become
crazy here. I can't believe after all the good things I've discovered
in Django that this can be so hard.
Thanks for your time
>
> You are right, I made a mist
>
> This always creates a new partner! In fact, in the ModelForm
> documentation is written that the save() method creates a new instance
> unless an existing instance is passed to the ModelForm constructor. So
> one has to differentiate if the POST comes from an initially empty
> form or from a bo
Hi again,
That's exactly what I did and the point is that it doesn't work! See
my comments below ...
On Jul 21, 8:00 pm, Shawn Milochik wrote:
> On Jul 21, 2009, at 12:49 PM, mettwoch wrote:
>
>
>
> > Sorry my old brain doesn't get it. Is there somewhere a complete CRUD
> > example using ModelF
On Jul 21, 2009, at 12:49 PM, mettwoch wrote:
>
> Sorry my old brain doesn't get it. Is there somewhere a complete CRUD
> example using ModelForm?
>
> Thanks
> Marc
CRUD:
If your modelform is called PartnerForm, then.
CREATE and UPDATE:
#on initial page load (no POST)
Sorry my old brain doesn't get it. Is there somewhere a complete CRUD
example using ModelForm?
Thanks
Marc
On Jul 21, 6:04 pm, Shawn Milochik wrote:
> On Jul 21, 2009, at 12:00 PM, mettwoch wrote:
>
>
>
>
>
> > Hi,
>
> > I'd like to implement a simple "create" & "update" form for my
> > "Partne
On Jul 21, 2009, at 12:00 PM, mettwoch wrote:
>
> Hi,
>
> I'd like to implement a simple "create" & "update" form for my
> "Partner" model using ModelForm. How can I make the difference in a
> view "save" function whether the POST comes from a "creation" or an
> "update" form? Unfortunately the
Hi,
I'd like to implement a simple "create" & "update" form for my
"Partner" model using ModelForm. How can I make the difference in a
view "save" function whether the POST comes from a "creation" or an
"update" form? Unfortunately the primary-key seems never to be
included by default in the form
20 matches
Mail list logo