Understanding how to create django Models -


i followed examples on django website , understand idea django wants separate pieces of project 'apps'.

each 'app' has own models. if want create app allows users login , modify data (add/edit/delete), collection of books , collection of authors, need create apps this.

in case have 'app' books contains models.py, 2 model classes : book , author. book class have 1 of fields author = models.foreignkey(author).

so here questions:

  1. if create new app can models in app contain foreignkey fields models don't reside in same app?
  2. as mentioned, want have credentials 'table' allows users login. how accomplished? necessary start new 'app' 'users' user model?
  3. how 1 incorporate mysql features 'auto increment', 'non-unique index', , 'triggers' these modesl or have done manually or through mysql console/manager?

nothing prevents making relationships models in other apps. apps way group code in logical places. here example of how might reference 1 model located in different app.

say in module called myapp, can refer other models in other apps syntax similar following. in example, there exists user model inside of "auth" app.

class mymodel(models.model):     ....     user = models.foreignkey('auth.user') 

also see: https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.foreignkey

django has great , flexible user system comes built it. when start new project, default, create user table can used create, manage, , authenticate users.

here related information. (actually, example above shows relationship built-in user table.) don't have start new app defining users unless want customize default behavior of user framework.

django automatically increments primary key fields records. creates necessary database objects needed this. enforces unique fields if desired , allows bunch of other customizations. far i'm aware, django not support database triggers. believe "pythonic" way trigger things may in code. specifically, django/python manage actions take after others. that's thoughts, though.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -