django - Create fields based on another model -
i have user model fields. of them require feedback, correctly filled (if not, specific message displayed on user profile).
the problem is, how represent 'invalid' fields in database. idea create model (call extuser) onetoonefield user. , extuser should have same fields' names user, types boolean, determining whether field filled in correctly. example, if user has field called email:
email = models.charfield(max_length=100)
extuser have following field:
email = models.booleanfield(default=false)
here's problem approach. how supposed create fields in extuser? of course can create them manually, breaking of dry principle, , i'm not going that. question is, can add fields model dynamically, , have them in database (so assume require called before migrate)?
i have django 1.8 , don't want use external modules/libraries.
if has idea of how represent data in database, please add comment, not reply - question creating fields dynamically.
you need manually.
python not disallow behavior; can take @ this response on dynamically created classes, django not able interpret output. in particular, django relies on models create sql tables application, , there no way occur if model not statically defined.
in case, don't think have worry dry; if need separate model fields happen related to, different from, model, think it's ok.
finally, i'm unsure goal is, define functions can determine how "correct" fields of user are. how recommend solving problem (if applies).
Comments
Post a Comment