First I don't think you should be using the admin for such fine grained
control of your data formats.
BUT if you do want to do that you would want to do your validation in custom
admin forms. (created in your admin.py to do cleans on the data that's being
submitted)

Second I wouldn't do a manytomany with this, I would instead create an
inline on your userinfo model linking to phones. Then your Phone will have a
FK relationship to your UserInfo.

in models.py
class Phone(model.Models):
    number = models.CharField(max_lenth=25)

class UserInfo(model.Models):
    name = models.CharField(max_length=50)

in admin.py

from myproject.myapp.models import Phone, User
class PhoneInline(models.TabularInline):
   model = Phone

class UserAdmin(models.ModelAdmin):
    inlines = [PhoneInline, ]

admin.site.register(User, UserAdmin)


What you get with that is the ability for a user to dynamically add as many
phone numbers to a user as they want. Also you get the charfield (instead of
the select box, which is what you get from the M2M field)

n


On Tue, Sep 21, 2010 at 9:14 AM, Anton Danilchenko <
anton.danilche...@gmail.com> wrote:

> 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 XXXX. But, I
> need save phone in database in format 0XXXXXXXXXX (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<django-users%2bunsubscr...@googlegroups.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.

Reply via email to