Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 24, 2010 13:41:44

r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

manytomany and form


hello list. I have a model like this

--------------------------------------------------------
class Dcto(models.Model):
......
fk_dcto = models.ManyToManyField('self', blank=True, null=True)
--------------------------------------------------------
this create a this internal table with this fields
--------------------------------------------------------
id
from_dcto_id
to_dcto_id
--------------------------------------------------------

My problem appear when I save the formmodel. I want something like
this saved.
----------------------------------------------------
id | from_dcto_id | to_dcto_id
x | old_dcto 1 | new_dcto
x | old_dcto 2 | new_dcto
----------------------------------------------------

but I get this

----------------------------------------------------
id | from_dcto_id | to_dcto_id
x | old_dcto 1 | new_dcto
x | old_dcto 2 | new_dcto
x | new_dcto | old_dcto 1
x | new_dcto | old_dcto 2
----------------------------------------------------

Somebody know how can i solve this problem?
Another question. I prefer a CheckboxSelectMultiple(), no a
selectMultiple(), I can define this in the widget meta,
--------------------------------------------
widgets = {
'fk_dcto':forms.widgets.CheckboxSelectMultiple(),
--------------------------------------------
but the user selection isn't saved.

Thanks for read, and sorry for my poor english.

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

Offline

#2 Dec. 24, 2010 13:51:51

r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

manytomany and form


to the first question, symmetrical=False, with this generate an
inverted information.
I want this.
----------------------------------------------------
id | from_dcto_id | to_dcto_id
x | old_dcto 1 | new_dcto
x | old_dcto 2 | new_dcto
----------------------------------------------------
but I get this
----------------------------------------------------
id | from_dcto_id | to_dcto_id
x | new_dcto 1 | old_dcto 1
x | new_dcto 2 | old_dcto 2
----------------------------------------------------

I need that every new dcto select his parents, to delimite the actions
over himself, not a parent defining his childs.

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

Offline

#3 Dec. 24, 2010 14:54:00

r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

manytomany and form


finally I do this

--------------
class form(forms.ModelForm):
fk_dcto = forms.ModelMultipleChoiceField(queryset= ....,
required=False, widget=forms.CheckboxSelectMultiple)
--------------
with this I can save with checkboxselectmultiple.

To define a correctly order to the many to manyfields in the form
declaration I do this.
----------------------------
def clean_fk_dcto(self):
self.fk_dcto_copy = self.cleaned_data.get('fk_dcto')
return

def save(self, *args, **kwargs):
newRow = super(Myform, self).save(*args, **kwargs)

for item in self.fk_dcto_copy:
item.fk_dcto.add(newRow)
item.save()
return oti

----------------------------

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

Offline

Board footer

Moderator control

Enjoy the 19th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support