Saturday, June 10, 2017

Re: Same form saving to related models

On Saturday 10 June 2017 15:42:50 Elorm Koku wrote:

> Melvin thanks, actually my models are simplified...the switch of fk

> was a way of trying to use it at d front end so that I could provide

> an id to link em up...unfortunately I can't go around it since an

> instance of the model is not easily accessible cos its a new object

> not saved yet...

 

This is all handled for a ManyToManyField in the admin and can be customized using InlineModelAdmin.

 

It can be done in the front-end using InlineFormSet.

 

 

> I thought of using a widget form to add up a parent

> later but I think yingis suggestions are smoother

>

> On Jun 10, 2017 2:39 PM, "Melvyn Sopacua" <m.r.sopacua@gmail.com> wrote:

> > On Saturday 10 June 2017 13:20:11 yingi keme wrote:

> > > The variable for foreign key is supposed to be declared under

> > > Student

> > >

> > > model because parents can typically have more than one kid in a

> > >

> > > school isnt it?

> >

> > And typically, students can have more then one parent. So either

> > rename your Parent model as Parents (plular) to indicate that you

> > use one object to describe two natural persons (and indeed, switch

> > the foreign key) - or - use a ManyToMany as both sides of the

> > relation can be linked to more then one of the other.

> >

> >

> >

> > In practice having one object for two Parents isn't ideal, as half

> > of the parents end up in the divorce, so contact details and so on,

> > become a mess again.

> >

> >

> >

> > ManyToManyField is the best fit here.

> >

> >

> >

> > --

> >

> > Melvyn Sopacua

> >

> > --

> > 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+unsubscribe@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/1653535.zO1WQPNAma%40devstation

> > <https://groups.google.com/d/msgid/django-users/1653535.zO1WQPNAma%4

> > 0devstation?utm_medium=email&utm_source=footer> .

> > For more options, visit https://groups.google.com/d/optout.

 

--

Melvyn Sopacua

No comments:

Post a Comment