ManyToManyField to Phones model for enter phones manually (not select from list)
Hi all! Please, help me undestand, how to solve next task. I am show for user form with two fields: user name and text field, where user input list of phones, separated by comma. User sholud enter one or more phones separated by comma. If user enter not valid number - we show error message like this "Phone 12345 is not valid. Please, enter valid phone numbers separated by comma". I have next two models: class Phone(models.Model): number = models.CharField(max_length=20) class UserInfo(models.Model): name = models.CharField(max_length=70) phones = models.ManyToManyField(Phone) User should enter numbers in CharField in format 0XX XXX . But, I need save phone in database in format 0XX (only number without spaces and other non-numbers digits). Please, can you help me in this. I am new in Django, and I am read more articles and not found solution. I think that I need create custom fields for form and model. P.S. Also, in admin section I should see CharField instead of ManyToManyField. -- 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 at http://groups.google.com/group/django-users?hl=en.
Re: ManyToManyField to Phones model for enter phones manually (not select from list)
In my case, I have Users with equal phone numbers. And I need only ManyToMany relationship. I need create custom field for get information from CharFiels, validate this data, clean and save to datastore in separate model. If this phone already exists - we get ID of this phone. And, if this is a new phone number - we insert this phone to separate model and get new ID. -- 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 at http://groups.google.com/group/django-users?hl=en.
Re: ManyToManyField to Phones model for enter phones manually (not select from list)
I describe my task more reallistical. This is application for rent an apartment. User can create new message with information about apartment, and also add one or more contact phone numbers. One user, without registration, can create more that one message on the site. For one message can add one phone number, for other message add two phones. I need to save only one copy of phone number in database in format . For each phone I can set if this phone in black list or not (model Phone have property "blocked" by default setted to False). I want to save phone numbers in model Phone, and messages in model Message. But, people can see input text field (CharField) where enter one or more phone numbers separated by comma. class Phone(models.Model): number = models.CharField(max_length=20) blocked = models.BooleanField(default=False) class Message(models.Model): # ... information about count of rooms, floor, cost, etc ... phones = models.ManyToManyField(Phone) Nick, thank you for you help. You are really very good people! On 21 сен, 18:12, "nick.l...@gmail.com" wrote: > Maybe I don't understand your problem. > > It sounds to me like your trying to make this way more difficult than it > needs to be. > > Also it sounds to me like your trying to assign the same phone number to > multiple people. (which is fine) But doesn't make a lot of sense to me in a > practical application. > > n > > On Tue, Sep 21, 2010 at 9:59 AM, Anton Danilchenko < > > > > > > anton.danilche...@gmail.com> wrote: > > In my case, I have Users with equal phone numbers. And I need only > > ManyToMany relationship. > > > I need create custom field for get information from CharFiels, > > validate this data, clean and save to datastore in separate model. If > > this phone already exists - we get ID of this phone. And, if this is a > > new phone number - we insert this phone to separate model and get new > > ID. > > > -- > > 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 > groups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. > > -- > Guadajuko! Vamos a correr! > -"Cool! we are going to run!" -- 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 at http://groups.google.com/group/django-users?hl=en.
Re: ManyToManyField to Phones model for enter phones manually (not select from list)
Also I need get list of all phones as with many-to-many relationship: m = Message.objects.get(1) for phone in m.phones: ptint phone On 21 сен, 20:15, Anton Danilchenko wrote: > I describe my task more reallistical. > > This is application for rent an apartment. User can create new message > with information about apartment, and also add one or more contact > phone numbers. One user, without registration, can create more that > one message on the site. For one message can add one phone number, for > other message add two phones. > > I need to save only one copy of phone number in database in format > . For each phone I can set if this phone in black list or not > (model Phone have property "blocked" by default setted to False). > > I want to save phone numbers in model Phone, and messages in model > Message. But, people can see input text field (CharField) where enter > one or more phone numbers separated by comma. > > class Phone(models.Model): > number = models.CharField(max_length=20) > blocked = models.BooleanField(default=False) > > class Message(models.Model): > # ... information about count of rooms, floor, cost, etc ... > phones = models.ManyToManyField(Phone) > > Nick, thank you for you help. You are really very good people! > > On 21 сен, 18:12, "nick.l...@gmail.com" wrote: > > > > > Maybe I don't understand your problem. > > > It sounds to me like your trying to make this way more difficult than it > > needs to be. > > > Also it sounds to me like your trying to assign the same phone number to > > multiple people. (which is fine) But doesn't make a lot of sense to me in a > > practical application. > > > n > > > On Tue, Sep 21, 2010 at 9:59 AM, Anton Danilchenko < > > > anton.danilche...@gmail.com> wrote: > > > In my case, I have Users with equal phone numbers. And I need only > > > ManyToMany relationship. > > > > I need create custom field for get information from CharFiels, > > > validate this data, clean and save to datastore in separate model. If > > > this phone already exists - we get ID of this phone. And, if this is a > > > new phone number - we insert this phone to separate model and get new > > > ID. > > > > -- > > > 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 > > groups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/django-users?hl=en. > > > -- > > Guadajuko! Vamos a correr! > > -"Cool! we are going to run!" -- 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 at http://groups.google.com/group/django-users?hl=en.
Re: ManyToManyField to Phones model for enter phones manually (not select from list)
Message - this is a rental proposition (rooms, floor, cost, area, country, cirty and contact phones). Visitors can create new messages (message - this is a rent proposition) and enter list of own phones (one or more phones). My application store this phones not in char field, but save each phone number to separate Phone morel - one phone in one model). If phone already exists - message attached to this phone. If phone not exists - we create new phone and attach message to this phone number. In future, I tell to people - and see that this people not a good man :-). I go to my application and mark this phone number to black list. All future messages from this people to be marked as bad messages. Now I need to create own Form field called MultiPhoneField based on CharField widget, but implenet logic of ManyToManyField. I need show for user CharField where user enter comma separated phone numbers. I check this numbers and if all numbers correct - store this numbers in database in Phone model (each phone in separate record) and associate message with list of this phones. Can you please help me in this. I not understand how to create my own Field based on ManyToManyField. Thanks! On 21 сен, 21:16, "nick.l...@gmail.com" wrote: > PersonallyI don't like the idea of adding multiple phone numbers as > comma separated values. What happens when a user's trying to add more phone > numbers than your charField's max_length? > > So let me see if I understand what's going on here... > > You have a problem where exists apartments for rent. People who want to rent > these apartments will send messages to the owner of said apartment (through > your website). This message will have associated to it, a User and Multiple > Phone Numbers. > > This message is then checked to see if the phone numbers associated to it > have been black listed... > And then finally deliver the message? > > n > > On Tue, Sep 21, 2010 at 12:15 PM, Anton Danilchenko < > > > > > > anton.danilche...@gmail.com> wrote: > > I describe my task more reallistical. > > > This is application for rent an apartment. User can create new message > > with information about apartment, and also add one or more contact > > phone numbers. One user, without registration, can create more that > > one message on the site. For one message can add one phone number, for > > other message add two phones. > > > I need to save only one copy of phone number in database in format > > . For each phone I can set if this phone in black list or not > > (model Phone have property "blocked" by default setted to False). > > > I want to save phone numbers in model Phone, and messages in model > > Message. But, people can see input text field (CharField) where enter > > one or more phone numbers separated by comma. > > > class Phone(models.Model): > > number = models.CharField(max_length=20) > > blocked = models.BooleanField(default=False) > > > class Message(models.Model): > > # ... information about count of rooms, floor, cost, etc ... > > phones = models.ManyToManyField(Phone) > > > Nick, thank you for you help. You are really very good people! > > > On 21 сен, 18:12, "nick.l...@gmail.com" wrote: > > > Maybe I don't understand your problem. > > > > It sounds to me like your trying to make this way more difficult than it > > > needs to be. > > > > Also it sounds to me like your trying to assign the same phone number to > > > multiple people. (which is fine) But doesn't make a lot of sense to me in > > a > > > practical application. > > > > n > > > > On Tue, Sep 21, 2010 at 9:59 AM, Anton Danilchenko < > > > > anton.danilche...@gmail.com> wrote: > > > > In my case, I have Users with equal phone numbers. And I need only > > > > ManyToMany relationship. > > > > > I need create custom field for get information from CharFiels, > > > > validate this data, clean and save to datastore in separate model. If > > > > this phone already exists - we get ID of this phone. And, if this is a > > > > new phone number - we insert this phone to separate model and get new > > > > ID. > > > > > -- > > > > 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 > > > groups.com> > > &
Re: ManyToManyField to Phones model for enter phones manually (not select from list)
Thanks. I have read this article. In my Form I have added validation for check phone numbers. All right - I show user error message if given incorrect phone number. This is simple. I need to save this phone numbers in model Phone if all phone numbers valid and all other fields in this form is valid. If one of the fields in this form is incorrect I don't save any phone in Phone model. As I see, ManyToManyField need get list of Phone IDs. But, actually I have only full phone numbers in format 01234567. I need to get ID for each phone (or create new record in table Phone). After this I need to get list of Phone IDs and pass this data to ManyToManyField. How can I do this? Thanks. On 21 сен, 23:21, "nick.l...@gmail.com" wrote: > read this here I think this'll explain what you're wanting. > > http://docs.djangoproject.com/en/dev/ref/forms/validation/ > > On Tue, Sep 21, 2010 at 1:50 PM, Anton Danilchenko < > > > > > > anton.danilche...@gmail.com> wrote: > > Message - this is a rental proposition (rooms, floor, cost, area, > > country, cirty and contact phones). > > > Visitors can create new messages (message - this is a rent > > proposition) and enter list of own phones (one or more phones). My > > application store this phones not in char field, but save each phone > > number to separate Phone morel - one phone in one model). If phone > > already exists - message attached to this phone. If phone not exists - > > we create new phone and attach message to this phone number. > > > In future, I tell to people - and see that this people not a good > > man :-). I go to my application and mark this phone number to black > > list. All future messages from this people to be marked as bad > > messages. > > > Now I need to create own Form field called MultiPhoneField based on > > CharField widget, but implenet logic of ManyToManyField. I need show > > for user CharField where user enter comma separated phone numbers. I > > check this numbers and if all numbers correct - store this numbers in > > database in Phone model (each phone in separate record) and associate > > message with list of this phones. > > > Can you please help me in this. I not understand how to create my own > > Field based on ManyToManyField. > > > Thanks! > > > On 21 сен, 21:16, "nick.l...@gmail.com" wrote: > > > PersonallyI don't like the idea of adding multiple phone numbers as > > > comma separated values. What happens when a user's trying to add more > > phone > > > numbers than your charField's max_length? > > > > So let me see if I understand what's going on here... > > > > You have a problem where exists apartments for rent. People who want to > > rent > > > these apartments will send messages to the owner of said apartment > > (through > > > your website). This message will have associated to it, a User and > > Multiple > > > Phone Numbers. > > > > This message is then checked to see if the phone numbers associated to it > > > have been black listed... > > > And then finally deliver the message? > > > > n > > > > On Tue, Sep 21, 2010 at 12:15 PM, Anton Danilchenko < > > > > anton.danilche...@gmail.com> wrote: > > > > I describe my task more reallistical. > > > > > This is application for rent an apartment. User can create new message > > > > with information about apartment, and also add one or more contact > > > > phone numbers. One user, without registration, can create more that > > > > one message on the site. For one message can add one phone number, for > > > > other message add two phones. > > > > > I need to save only one copy of phone number in database in format > > > > . For each phone I can set if this phone in black list or not > > > > (model Phone have property "blocked" by default setted to False). > > > > > I want to save phone numbers in model Phone, and messages in model > > > > Message. But, people can see input text field (CharField) where enter > > > > one or more phone numbers separated by comma. > > > > > class Phone(models.Model): > > > > number = models.CharField(max_length=20) > > > > blocked = models.BooleanField(default=False) > > > > > class Message(models.Model): > > > > # ... information about count of rooms, floor, cost, etc ... > > > > phones = models.ManyToManyField(Phone) > > > > > Nick, thank you for you help. You
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 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-us...@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: ManyToManyField to Phones model for enter phones manually (not select from list)
Ihave found solution. I have changed only Form class: 1) added field for show text input field phones = forms.CharField() 2) I have create in my Form instance method clear_phones() where I check phones and save it all to database and get Phone model ids for this phone numbers. And return this ids All work well. Simple solution for this task. Thank you for help! -- 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 at http://groups.google.com/group/django-users?hl=en.
Include form in template tag
Hi! I have created templatetag (used Django 1.2.3) in templatetags/ board.py file. I need import form class from application. Structure of project is: + board/ +++ views.py +++ forms.py +++ templatetags/ + board.py + ... some other project applications ... How can I do import of form from the file forms.py? I try to do this: 1) from models import Message 2) from board.models import Message 3) from myprojectname.board.models import Message All this not work and show error message like this: "'board' is not a valid tag library: ImportError raised loading board.templatetags.board: No module named models" Please help. -- 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 at http://groups.google.com/group/django-users?hl=en.
Re: Include form in template tag
In my case this work well: from ..forms import MessageSearchForm Maybe we have other solution for this? On 23 сен, 16:46, Anton Danilchenko wrote: > Hi! > > I have created templatetag (used Django 1.2.3) in templatetags/ > board.py file. I need import form class from application. > > Structure of project is: > + board/ > +++ views.py > +++ forms.py > +++ templatetags/ > + board.py > + ... some other project applications ... > > How can I do import of form from the file forms.py? > > I try to do this: > 1) from models import Message > 2) from board.models import Message > 3) from myprojectname.board.models import Message > > All this not work and show error message like this: "'board' is not a > valid tag library: ImportError raised loading > board.templatetags.board: No module named models" > > Please help. -- 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 at http://groups.google.com/group/django-users?hl=en.
Bug in django admin: list_editable should be not editable if appear in readonly_fields
Hello dev team! I think that if some field set to *readonly_fields* than we should display disabled field in *list_editable*. Now I have set field "*price*" into *list_editable* and *readonly_fields*. And I see this field not editable in "change view" in admin panel, but I see it editable in "list view". If field not editable - I should not edit this field in admin site. But, as I can see - I can edit this field in "list view", that creates some problems. Because it isn't what I wan to see. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/702c9d44-a8b3-4826-a242-31e36ce27813%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.