Wednesday, September 22, 2010

Re: ManyToManyField to Phones model for enter phones manually (not select from list)

Now I have next solution (but still need your help).

1) I have added to my form custom field CharField for render field as
input <type="text">

2) I have created Form method clean_phones() for check all values is
valid

3) in views.py I have get field contents, split it by comma and delete
all non-numbers. In result I have list of phones in format 01234567

4) in views.py I create Phone model record for each phone
phones = ['01234567', '45678921']
ids = []
for phone in phones:
ids.append(Phone.objects.get_or_create(number=phone))

5) pass ids to real form field - ManyToManyField called phones


Please, help me understand how to pass all this logic in one place -
in custom field.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate