python - Django models kind of multi-table inheritance not working -


I want to create a hierarchy based on the Dmax design as described in the "Basic Principles of Database Systems" from Almastri & amp; is. Navathe

This means that when I have some information that is shared for many classes / tables, then I can put it in the main parent table and the main table id in the hair tables with the foreign key Weak unit can be used in the form.

I have tried to use intangible and multivable inheritance (this last one has not given me the one named Vinoinfield, it is not known where it is on the Digengo docs).

My example here is correct (one table per square):

  '' 'I would like it to be abstract, because I will not ever wait for it, but if needed If not, then the class person (models.Model): personId = models.IntegerField (primary_key = True) name = models.CharField (max_length = 45) surname = models.CharField (max_length = 45, empty = True) Email = Model. Wheatfield (max_length = 45, empty = true) Phone = Model Classroom Meta: Managed = Wrong dB_table = 'Person' category scholarship (person): # maybe it should be one below OneToOne # AlumnId == The person is always the same real world boy The truth is for alumni = model.Agariniki ('person', 'db_column =' alumnId ', primary_key = true) Comments = Model.Carfield (max_length = 255, empty = true) Class meta: managed = wrong db_table =' alumn ' # There are more child classes (client, professor, Etc ....) # But for example it is sufficient   

My goal is to get a scholarship in DB with only two sentences:

  a = scholarship (person = 1, name = 'joe', [... more parameters ...], alumid = 1, comments = 'some comments') a.save ()  < / pre> 

and insert these two lines into two rows: Alumnus iid specials for this person and for a student in this snippet So can be skipped, because it will always be the person (I told you such a weak entity).

I am starting a lot on the Denggo, but I have seen the document and some things have been proven true in the abstract = person and due to not being successful, now I feel that I am a superstar. To make the construction should be confused with the init constructors and after this the child class should be constructed.

I do not have the right way to choose but definitely do not want to change the database design. help please.

Thanks in advance.

You do not need to have an ID in your model; Besides Django handle it automatically, besides you do not want to use the case of camel. In other words: personId person_ID should be and not necessarily anyway - just remove it.

In general, I avoid non-abstract legacy with an ORM.

I really can not understand what you want to achieve but depending on your needs, I suggest 2 approaches (person, alumnus, professor, etc.):

1. Essence inherited:

  class person: class meta: abstract = truth # Here you add all the normal columns   

then: Alumni of the class (person): # other column -

etc. for a specific category.

By doing this you have one table per person type: scholarship, professor etc.

Use 2 composition:

  Category category: person = model. University of Firozy (person, void = true, related_name = "alumni_at") = University ... ... professor: person = model ForeignKey (person, tap = true, related_name = "professor_at") = ...  < / pre> 

You can do this:

  Bob = Person objects.Scent (FirstName = "Bob", ...) Alum. Objects.Sent (person = Bob, University = "Univ 1") Professor.Objects.Sent (person = Bob, University = "University 2") Elam. Objects.create (person = Bob, University = "Univ 2")    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -