I think, you will need to implement something like below. Profile: first_name middle_name last_name birthday address (primary/default) email (primary/default) phone (primary/default)
Address <profile-foreign-key> address_line1 address_line2 City state zip Email <profile-foreign-key> email Phone <profile-foreign-key> phone As one profile can have multiple entries of addresses, email and phone numbers, you could use concept of formset to deal with them. Also, as there are multiple entries, you could store one of them as default or primary. I hope this helps :) Regards, Chetan Ganji +91-900-483-4183 ganji.che...@gmail.com http://ryucoder.in <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e> I’m protected online with Avast Free Antivirus. Get it here — it’s free forever. <https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> On Sun, Mar 31, 2019 at 3:56 AM Dean Karres <dean.kar...@gmail.com> wrote: > Hi > > I am looking for some advice. I have a basic Profile model. It looks > something like: > > Profile: > first_name > middle_name > last_name > birthday > address_line1 > address_line2 > city > state > zip > email > phone > > I have a ModelForm that goes with this. > > This is sufficient for nearly all the cases I am trying to deal with. > However, there are a few special cases in which a person needs to list two > or more addresses; two or more email addrs; two or more phone numbers; or, > combinations. > > I know just enough about database normalization to think that I need the > Profile model plus Address, Email and Phone models and have the Profile > have a ForeignKey relation to each of the others. A la: > > Profile: > first_name > middle_name > last_name > birthday > <address-foreign-key> > <email-foreign-key> > <phone-foreign-key> > > Address > address_line1 > address_line2 > City > state > zip > > Email > email > > Phone > phone > > My question is more about the associated ModelForm(s). First, I currently > have a ModelForm for the first Profile model without the foreign keys. If > I break out the address, email and phone portions into separate models do I > need to create separate model forms for each new model? If so would the > new Profile ModelFOrm just inherit the ModelForms of the other components. > Something like: > > class ProfileForm(ModelForm, AddressForm, EmailForm, PhoneForm): > ... > > The current ModelForm has "clean_<field>" "clean" methods. Do I keep that > in the new Profile form? Do I put the various "clean" methods in their own > model forms and hope that inheritance will pull them in? > > Next, how does a ModelForm deal with more than one of the same item -- > like more then one address? > > -- > 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 https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/a8954cd8-e3c6-4d6f-8780-1f88a9874a3b%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/a8954cd8-e3c6-4d6f-8780-1f88a9874a3b%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjuXoHKh9CwOe%3DG78mJhQUvw19Uva2hUORKxgCtbReuXNw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.