Re: ModelFormSet and model deletion

2009-02-11 Thread Sergey Koval
Probably connected issue: when I check generated SQL when saving form with
inline ModelFormSet, I'm getting following SQL queries:

SELECT (1) AS "a"
FROM "table1"
WHERE ("table1"."id" = 8 AND NOT ("table1"."id" = 8 ))

 8 is valid id and "delete" checkbox is not checked. There's always at least
one query per item. Probably it is check if model still exists in the
database, but doubt that generated query is correct. I'm using SQLite as a
database provider.

Serge.

On Wed, Feb 11, 2009 at 5:40 PM, Sergey Koval <serge.ko...@gmail.com> wrote:

> Hello,
>
>  I want to use ModelFormSet's model delete capability and here's problem I
> encountered: when I render formset manually (by looping through
> formset.forms), and if model was deleted, form is not getting deleted from
> formset.forms list. If I refresh whole page, deleted ModelForm disappears.
> Is it a bug or proper behavior? I'm using Django 1.0.2.
>
> P.S. Yes, I can create formset again after saving data to the database, but
> it is just temporary solution.
>
> Thanks,
> Serge.
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ModelFormSet and model deletion

2009-02-11 Thread Sergey Koval
Hello,

 I want to use ModelFormSet's model delete capability and here's problem I
encountered: when I render formset manually (by looping through
formset.forms), and if model was deleted, form is not getting deleted from
formset.forms list. If I refresh whole page, deleted ModelForm disappears.
Is it a bug or proper behavior? I'm using Django 1.0.2.

P.S. Yes, I can create formset again after saving data to the database, but
it is just temporary solution.

Thanks,
Serge.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: m2m field and forms

2009-02-10 Thread Sergey Koval
On Tue, Feb 10, 2009 at 1:21 PM, Konstantin S  wrote:

>
> Hello
>
> I have a form created from forms.ModelForm and in my model one of the
> fields is m2m field. Now when form is displayed for that m2m filed I'd
> like to have something that looks like checkbox where user can select
> several alternatives. I know that I can use widgets here and there are
> some that can be used in my case, but I don't know how do I use them
> in case of form being generated as ModelForm ?

If you want to show multiple checkboxes, use CheckboxSelectMultiple widget.

Sample code:

class MyForm(forms.ModelForm):
my_field = fields.ModelMultipleChoiceField(queryset=your_query_set,
widget=forms.CheckboxSelectMultiple)

--
Serge

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Forms, fields and widgets

2009-02-10 Thread Sergey Koval
On Tue, Feb 10, 2009 at 10:14 AM, Malcolm Tredinnick <
malc...@pointy-stick.com> wrote:

> Your constraints are a bit arbitrary and, in fact, overly-restrictive.
> In particular the "without changing ModelForm" wish is just that: a
> hope, not something that falls out of the design as "it looks like this
> must be possible." A ModelForm is a form that maps each model field to a
> particular form field. That's all. It's not a prototype for arbitrary
> model -> form mappings. Rather, it implements one particular sort of
> (commonly useful) mapping.

Indeed. And it also has special rules for foreign and m2m model fields. At
the moment, for foreign key, model instance will be replaced with model id.
And that's a bit restrictive.


> I wouldn't be thinking about this from the widget level. Widgets are
> just the rendering side. The better question is how to construct a form
> class that allows you to specify form fields which can work with this
> information. You're asking how to create a particular sort of form field
> (Django-form field, not HTML-form field) here. The final rendering, via
> Django-form widgets, will almost certainly just use normal (existing)
> widgets.

  That's correct. I just want to have possibility for my custom form fields
to participate in initial_data generation process (that's how ModelForm
captures data from the model instance).
  Problem is in asymmetry: field which surely works only with models
(ModelChoiceField/ModelMultipleChoiceField) is used to convert raw data
(model id) to appropriate model instance, but not vice a versa. So I can
create field that will "clean" raw data to model of my choice with some
additional logic applied, but in order to do reverse conversion (from model
to raw data) - I have to change ModelForm itself. That's what was bugging me
:-)


> I haven't worked out an answer, in terms of code, to your problem yet,
> beyond thinking it didn't seem to hard. I'll try to find some time
> tonight to work out some specifics and post tomorrow if nobody else
> comes up with a passable solution. But, in the interests of
> understanding the issue properly, I would suggest you spend a bit more
> time thinking about this yourself, based on the lines I've written
> above, rather than hoping somebody might give you the answer outright in
> such a short space of time.
>
No need to, thank you. I know how to do it (by overriding default ModelForm
behavior). It was more of the

Thanks,
Serge.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Forms, fields and widgets

2009-02-09 Thread Sergey Koval
Hello,

 I read mentioned thread and still can't figure out how I can pass arbitrary
values to widgets.
OK, I'll rephrase question (it was "task" in the previous email): how I can
make widget that takes two values out of the model without changing
ModelForm behavior or doing separate query in the widget?

 Probably it is bad mailing list to ask such questions, should I go to devel
instead?

Thanks,
Serge.

On Tue, Feb 10, 2009 at 12:21 AM, Alex Gaynor  wrote:

>
>
> On Mon, Feb 9, 2009 at 5:18 PM, Serge S. Koval wrote:
>
>>
>> Hello,
>>
>>  I'm fairly new Django user, but have some background experience with
>> other frameworks. Sorry if this topic was discussed before, but I was
>> not able to find any mention of it.
>>
>>  My question is related to architectural decisions of the forms,
>> fields and widgets.
>>
>>  At the moment in Django, all "incoming" data is processed by the
>> widget and clean by the field. Data flow: raw data -> widget -> field ->
>> form.
>>  However, reverse process is different: data -> form -> widget
>> data. As you can see, field does not play and role in reverse data
>> conversion.
>>
>>  Let's examine simple task. ModelForm calls model_to_dict() to
>> initialize form fields with initial data. In case of models data is
>> their id's.
>>  But what if one will want to develop widget that requires more
>> than just a model id? For example: str(model) and model.id at the same
>> time? There are not so many options how it can be done right now: or
>> derive from ModelForm and override it's data gathering behavior
>> (rewrite model_to_dict()) or run extra query in the widget itself (which
>> is not optimal).
>>
>>  Possible naive solution: if it would be possible to make field work in
>> _both_ directions, it would be awesome.
>>  If field will know that it works with models (like ModelForm related
>> fields), it will be responsible for cleaning data to the
>> widget-appropriate format.
>>
>>  It is my two cents. I don't know if somebody already tried to make it
>> work this way of there were some reasons not to do this way... I don't
>> know.
>>
>>  Thanks,
>> Serge.
>>
>> --
>> Best regards,
>>  Serge  mailto:serge.ko...@gmail.com
>>
>>
>>
>>
> I would recommend searching the dev list for a thread titled: "Controlling
> form/widgets output".
>
> Alex
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---