Tuesday, June 3, 2014

Re: editable models (db schema) for admin (no developer)

Am 03.06.2014 16:27, schrieb Erik Cederstrand:
> Den 03/06/2014 kl. 15.57 skrev Thomas Güttler <hv@tbz-pariv.de>:
>
>> I am a software developer and like the way django ORM defines the database (via models.py) very much.
>>
>> Unfortunately for a new project, we have the constraint, that the admin must be able
>> to add some columns. The admin is not a developer, and he only uses a web interface.
>>
>> I don't want to make model.py files editable via an admin interface, since running migrations and all
>> that does not fit into "web editable".
>
> Are you *really* sure you want to do this? Monkey-patching running code, adding class attributes and inserting database columns on the fly to a production system isn't something recommended in textbooks. Try describing your situation a bit. Maybe you could use a key-value approach and m2m relations instead?

I am sure: I don't want it. I guess you have read my post too fast.

> Another possibility is that you avoid editing models.py by creating the new database column manually using raw SQL, so Django doesn't know about it. Then override __getattr__ on the model so my_obj.extra_col_123 circumvents the ORM and fetches data by other means, or simply issue raw SQL when you need to access 'extra_col_123' in your code.

Yes, this would be a solution.

Thank you for your feedback.

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/538DDCE5.2000108%40tbz-pariv.de.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment