Wednesday, June 27, 2012

Re: ManyToManyField is this right?

On 6/27/12 11:48 AM, David Wagner wrote:
Looking at that I think I may need to add a foreignkey to cert_types relating to person since a person can have multiple certification types (NRA Instructor, CCL Instructor, etc).
No. See below.

On Wed, Jun 27, 2012 at 11:40 AM, David Wagner <cptnwinky@gmail.com> wrote:
i think I may just be over thinking this. The last time I did any significant coding for the web as pre-php5 and so this whole MVC thing is something to adapt too for sure.
Yes you are :)

I think I need to start thinking of the Model in the same way I would design a database back in the day with phpMyAdmin. I think I'm getting bogged down in trying to understand how it will relate to the View. Perhaps I need to just put the View out of my mind for the time being.
Yes. If you've done databases (that is some of my background too) then the models (always the first step here) should become comfortable fairly quickly, even if you are rusty. See below...

So thinking of this as just a database schema it would be something like (in psuedo-code)....

cert_types
  • type
  • date_created

certs

  • type = foreignkey(cert_types)
  • name
  • state (optional)
  • date_created

person

  • name
  • etc...
  • certificates = foreignkey(certs)
OK, "cert_types" is good (or at least a good start). "person" needs to have a manytomany on cert_types rather than a foreign key on certs. And "certs" can be the explicit intermediate table used for the manytomany relationship and can hold things like dates. Look at the django docs on how to explicitly define the intermediate table, but it is in the musician and musical group example; google for "paul ringo django extra fields" :)

hth

                             - Tom

No comments:

Post a Comment